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' ) );
精彩评论