我在页脚中创建了一个表。
我想展示一些统计数据,比如总帖子、每周帖子、特定类别的总帖子。
我只是用wp_count_posts()->publish;
我能为另一个做些什么?
我在页脚中创建了一个表。
我想展示一些统计数据,比如总帖子、每周帖子、特定类别的总帖子。
我只是用wp_count_posts()->publish;
我能为另一个做些什么?
你已经拥有了全部帖子,所以为了在上周内获得全部帖子,最好在你的functions.php
文件:
function get_posts_count_from_last_week($post_type =\'post\') {
global $wpdb;
$numposts = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(ID) ".
"FROM {$wpdb->posts} ".
"WHERE ".
"post_status=\'publish\' ".
"AND post_type= %s ".
"AND post_date> %s",
$post_type, date(\'Y-m-d H:i:s\', strtotime(\'-168 hours\'))
)
);
return $numposts;
}
然后在页脚中使用它。<?php echo get_posts_count_from_last_week(); ?>
使用我们可以使用的类别WP_Query:$args = array(
\'cat\' => 4,
\'post_type\' => \'videos\'
);
$the_query = new WP_Query( $args );
echo $the_query->found_posts;
Wordpress查询支持Date Query.要获取特定类别,还需要添加category参数。
我创建了新的帖子类型(酒店)和分类法(本地化)。我想通过分类法的计数描述循环我的酒店订单。我想按本地化数量对我的酒店进行排序(我指的是从本地化中的更多酒店到更少酒店的订单)。我尝试以下方法: $args = array( \'post_type\' => \'hotels\', \'posts_per_page\' => -1, \'tax_query\' => array( a