0

I have blog post counts which happen when a user views a blog post via ajax and the rest api.

In the database I have a meta key and value like so:

table: wp_postmeta
post_id: blog post ID
meta_key: blog_post_count
meta_value: number ie: 1, 2, 3 etc. 

This basically stores the blog post ID and the count. On a page, I am trying to display the ID with the highest count only.

$views = new WP_Query( array(
    'orderby' => 'meta_value_num',
    'meta_key' => 'blog_post_count',
    'order' => 'DESC',
    'posts_per_page' => 1
) );

Running this in a standard wordpress loop however displays all posts and not with the highest count first so my Query is obviously not correct.

1 Answer 1

0
try changing 'orderby' => 'meta_value_num'  to 'orderby' => 'meta_value meta_value_num'

Your Answer

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

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