sort product catalog
-
How can I set the entire catalog (on the shop page and on category pages) by a custom field value?
My custom field is created by ACF and is called event_date.
Here’s what I tried:
function products_pre_get_posts( $query ) { // do not modify queries in the admin if ( is_admin() || !$query->is_main_query() ) return $query; // only modify queries for 'event' post type if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'product' ) { $query->set('orderby', 'meta_value'); $query->set('meta_key', 'event_date'); $query->set('order', 'DESC'); } // return return $query; } add_action('pre_get_posts', 'products_pre_get_posts');This sorts the shop page but not the category pages.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘sort product catalog’ is closed to new replies.