I am querying for most popular posts by custom view count by using the custom query below,
<?php
$mostpopular_args=array(
'post_type' => 'post',
'orderby' => 'meta_value_num',
'meta_key' => 'view_count',
'posts_per_page' => 2,
);
<?php $mostpopular_pick = new WP_Query($mostpopular_args); ?>
?>
However, this is not working. As suggested by an expert, I ran $mostpopular_pick->request
and it seems that wordpress is ordering posts by 'menu_order' instead of meta_value_num. Here is what it returned,
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
WHERE 1=1
AND wp_posts.post_type = 'post'
AND (wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'private')
AND (wp_postmeta.meta_key = 'view_count')
GROUP BY wp_posts.ID
ORDER BY wp_posts.menu_order,
wp_postmeta.meta_value DESC LIMIT 0,
2
And also, though I limited post count to 2, it is still returning 4 posts.
Whats going on, any Idea?