开发者

how to sort posts (sort by views) using post_views_count function?

i want to sort posts (sort by views) using this function

i am using this code in function.php to get post views count

<?php
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
    delete_post_meta($postID, $count_key);
    add_post_meta($postID, $count_key, '0');
    return "0 View";
}
return $count.' Views';
}
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
    $count = 0;
    delete_post_meta($postID, $count_key);
    add_post_meta($postID,开发者_如何学编程 $count_key, '0');
}else{
    $count++;
    update_post_meta($postID, $count_key, $count);
}
}
?>

like this way

 &orderby=comment_count&order=desc
 &v_sortby=views&v_orderby=desc


I think you can use this query:

$new_posts = new WP_Query( array( 'meta_key' => 'post_views_count', 'orderby'=> 'meta_value', 'order' => 'desc' ) );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜