我想使用此功能对帖子进行排序(按视图排序)
我在function.php中使用此代码来获取帖子视图计数
<?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);
}
}
?>
像这样
&orderby=comment_count&order=desc
&v_sortby=views&v_orderby=desc
答案 0 :(得分:1)
我认为您可以使用此查询:
$new_posts = new WP_Query( array( 'meta_key' => 'post_views_count', 'orderby'=> 'meta_value', 'order' => 'desc' ) );