Wordpress Echo帖子数

时间:2018-08-23 09:44:33

标签: php wordpress slug

我有一个自定义帖子类型,其中包含多个属性, 如价格 彩色模型等。

希望Wordpress打印其中的帖子数量。

我当前的代码是这个

 // Get total number of posts in "vehiclestock" post type
$count_vehiclestock = wp_count_posts('listings');
$total_vehiclestock = $count_vehiclestock->publish;
echo $total_vehiclestock . ' listings. ';

我附了一些例子,以更好地说明自己。 因为我不知道该寻找什么来回答我自己的问题

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

添加此代码以计算所有帖子或按类别明智的帖子

$args = array(
      'posts_per_page' => -1,
      'post_type'=> 'post',
      'tax_query' => array(
                          array(
                              'taxonomy' => 'category',
                              'field'    => 'slug',
                              'terms'    => 'category_slug'
                          )
                      ),
    ); 
 $wp_query = new WP_Query( $args );

 $post_count = $wp_query->post_count;
相关问题