可以使用运行查询get_posts
要检索特定作者的帖子,并排除某些类别,然后使用count
返回帖子数量。get_posts
使用与相同的参数WP_Query
, 所以你可以看看那里的参数
<?php
$args = array(
\'author\' => 1 //ID of the author
\'posts_per_page\' => -1, //Retrieve all posts
\'category\' => -13, // Category to exclude, must be ID, as category is passed to WP_Query as cat
);
$posts_array = get_posts( $args );
echo count($posts_array); //Display post count