Sort by … ACF custom Field
-
Hello,
I’ve created categories (eg. “Rando”) and also custom fields with ACf (eg. “kilometrage”).
Now i try to sort my articles “km” by “kilometrage” and i put the code below in Code Snippets extension. I also try in my fonction.php file of my theme (Bateaux theme).
But that doesn’t work.
Could you please help me ?
Thanks a lotfunction my_pre_get_posts($query) { if(is_admin()) { return $query; } if(isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'km' && $query->is_main_query()) { $query->set('orderby', 'meta_value'); $query->set('meta_key', 'kilometrage'); $query->set('order', 'ASC'); } return $query; } add_action('pre_get_posts', 'my_pre_get_posts');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Sort by … ACF custom Field’ is closed to new replies.