如果要查询页面,必须选择post_type=page
- 当然
另一个“问题”是Commo count并不能准确地表示帖子/页面视图。如果您真的想要页面浏览量,而不是评论数,请尝试下面的功能-我从这里得到:http://wpsnipp.com/index.php/functions-php/track-post-views-without-a-plugin-using-post-meta/.
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);
}
}
这样,您就必须查询新的元键
post_views_count
. 就这样-祝你好运!