0

I have added a numeric field (called 'video_order') to a certain post type, via ACF.

I would like to sort the list of posts, by that numeric field. I have made sure to go through the posts and give them all a value.

This is the Query i have tried, which does not seem to work (there is just no sorting based on that numeric field)

Can someone suggest something?

Thanks!

$args = array( 
   'post_type' => 'post_sermons',
   'post_status' => 'publish',
   'posts_per_page' => ot_get_option('wpl_sermon_per_page'),
   'paged'=> $paged,
   'orderby' => 'video_order',
   'order' => 'ASC' 
);

1 Answer 1

5

Your meta key should be specified as the meta_key argument, and orderby should be meta_value_num:

$args = array( 
   'post_type' => 'post_sermons',
   'post_status' => 'publish',
   'posts_per_page' => ot_get_option('wpl_sermon_per_page'),
   'paged'=> $paged,
   'meta_key' => 'video_order',
   'orderby' => 'meta_value_num',
   'order' => 'ASC' 
);

See WP_Query for explanations of query arguments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.