i have created a page where i am sorting the post according to the views. Here is the query
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=12&order=DESC&orderby=meta_value_num&meta_key=cv_post_views_count&post_type=post'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
Post Html and content goes here
<div class="post-nav-container">
<?php previous_posts_link( __('→ Older Posts','circoviral')); ?>
<?php next_posts_link( __('← Older Posts','circoviral')); ?>
</div>
<?php
$wp_query = null;
$wp_query = $temp; // Reset
?>
This is a page template and also i need pagination for this page because this page is having infinite scroll.But when i see the output of the query on the pages , it is not returning me the posts in the manner i requested. Only the sorting is not working.
When i debug the wp_query , i got this
["query"]=>
array(6) {
["showposts"]=>
string(2) "12"
["order"]=>
string(4) "DESC"
["orderby"]=>
string(14) "meta_value_num"
["meta_key"]=>
string(19) "cv_post_views_count"
["post_type"]=>
string(4) "post"
["paged"]=>
string(1) "0"
}
Generated SQL Query
SELECT SQL_CALC_FOUND_ROWS cvr_posts.ID
FROM cvr_posts
INNER JOIN cvr_postmeta ON (cvr_posts.ID = cvr_postmeta.post_id)
WHERE 1=1
AND cvr_posts.post_type = 'post'
AND (cvr_posts.post_status = 'publish'
OR cvr_posts.post_status = 'private')
AND (cvr_postmeta.meta_key = 'cv_post_views_count')
GROUP BY cvr_posts.ID
ORDER BY cvr_postmeta.meta_value DESC LIMIT 0, 12
Aucun commentaire:
Enregistrer un commentaire