按 post 观看次数排序不起作用。插件:"Post Views Counter" - Wordpress
Sorting by post views count doesnt work. Plugin: "Post Views Counter" - Wordpress
我正在制作新闻博客,我需要显示每日帖子。
每日帖子在我的博客中如何运作?:我选择了这一天的所有帖子并按浏览量排序。
问题是:我无法使用 Post Views Counter 插件按观看次数排序。它不会返回 WP_Query.
上的任何帖子
我的尝试:
function DisplayDailyNews(){
$yesterday = date('d.m.Y',strtotime("yesterday"));
$yesterdayarray = date_parse($yesterday);
$dailyGridPostQuery = new WP_Query(array(
"post_type" => "post",
"post_status " => "publish",
"posts_per_page" => 3,
"day" => $yesterdayarray["day"],
"meta_key" => "post_views_count",
"orderby" => "meta_value_num",
"order" => "DESC"
));
if ($dailyGridPostQuery->have_posts()){
while ($dailyGridPostQuery->have_posts()){
$dailyGridPostQuery->the_post();
//Displaying post item here...
}
}
}
我尝试用谷歌搜索解决方案,但 none 对我有用。
FAQ1:是的,我有今天的帖子。
此插件不使用自定义字段 post_views_count 进行保存 post_count
它创建额外的 table
$wpdb->prefix . "post_views
要按 post_views 排序帖子,请使用
"orderby" => "post_views",
试试这个代码
$dailyGridPostQuery = new WP_Query(array(
"post_type" => "post",
"post_status " => "publish",
"posts_per_page" => 3,
"year" => $yesterdayarray["year"],
"monthnum" => $yesterdayarray["month"],
"day" => $yesterdayarray["day"],
"orderby" => "post_views",
"order" => "DESC"
));
P.S。
post_views 需要 > 0
我正在制作新闻博客,我需要显示每日帖子。
每日帖子在我的博客中如何运作?:我选择了这一天的所有帖子并按浏览量排序。
问题是:我无法使用 Post Views Counter 插件按观看次数排序。它不会返回 WP_Query.
上的任何帖子我的尝试:
function DisplayDailyNews(){
$yesterday = date('d.m.Y',strtotime("yesterday"));
$yesterdayarray = date_parse($yesterday);
$dailyGridPostQuery = new WP_Query(array(
"post_type" => "post",
"post_status " => "publish",
"posts_per_page" => 3,
"day" => $yesterdayarray["day"],
"meta_key" => "post_views_count",
"orderby" => "meta_value_num",
"order" => "DESC"
));
if ($dailyGridPostQuery->have_posts()){
while ($dailyGridPostQuery->have_posts()){
$dailyGridPostQuery->the_post();
//Displaying post item here...
}
}
}
我尝试用谷歌搜索解决方案,但 none 对我有用。
FAQ1:是的,我有今天的帖子。
此插件不使用自定义字段 post_views_count 进行保存 post_count 它创建额外的 table
$wpdb->prefix . "post_views
要按 post_views 排序帖子,请使用
"orderby" => "post_views",
试试这个代码
$dailyGridPostQuery = new WP_Query(array(
"post_type" => "post",
"post_status " => "publish",
"posts_per_page" => 3,
"year" => $yesterdayarray["year"],
"monthnum" => $yesterdayarray["month"],
"day" => $yesterdayarray["day"],
"orderby" => "post_views",
"order" => "DESC"
));
P.S。 post_views 需要 > 0