Wp_Query
应该可以为你做这件事。传递适当的参数,包括tax_query
, 和检查found_posts
.
$p = new WP_Query(
array(
\'post_type\' => \'custcpt\', // your CPT
\'tax_query\' => array(
array(
\'taxonomy\' => \'custtax\', // your tax
\'field\' => \'id\',
\'terms\' => $cat->term_id, // your term ID
)
),
\'ignore_stickie_posts\' => true,
\'fields\' => \'ids\',
)
);
echo $p->found_posts;
未测试,但应接近。