I’m attempting to order my posts by a meta worth in order that I can present the most well-liked posts. However it’s returning the most recent posts as a substitute.
//WordPress loop for the customized publish sort
$popular_args = array(
'post_type' => 'video games',
'posts_per_page' => 6,
'suppress_filters' => true, //Simply in case one thing else is interfaring.
'orderby' => 'meta_value_num',
'meta_key' => 'view_54ygtt',
'order' => 'DESC',
'meta_query' => array(
array(
'sort' => 'NUMERIC'
)
),
);
$popular_query = new WP_Query($popular_args);
whereas ($popular_query->have_posts()) : $popular_query->the_post();
//Get the template
echo get_the_title() .' - '. get_post_meta($post->ID, 'view_54ygtt', true) .'<br>';
endwhile;
wp_reset_query(); ?>
Consequence:
Pattern Submit 6 – 1282
Pattern Submit 5 – 25719
Pattern Submit 4 – 88999
Pattern Submit 3 – 77354
Pattern Submit 2 – 7948
Pattern Submit 1 – 1526
It ought to be:
Pattern Submit 4 – 88999
Pattern Submit 3 – 77354
Pattern Submit 5 – 25719
Pattern Submit 2 – 7948
Pattern Submit 1 – 1526
Pattern Submit 6 – 1282