您可以使用WP\\u查询,特别是tax_query:
$args = array(
\'post_type\' => \'post\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => array( \'allow-list\' ),
),
array(
\'taxonomy\' => \'post_tag\',
\'field\' => \'slug\',
\'terms\' => array( \'cats\' ),
),
),
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$count = $the_query->found_posts;
echo \'Post count: \' . $count;
// echo \'<ul>\';
// while ( $the_query->have_posts() ) {
// $the_query->the_post();
// echo \'<li>\' . get_the_title() . \'</li>\';
// }
// echo \'</ul>\';
} else {
echo \'No posts found\';
}
/* Restore original Post Data */
wp_reset_postdata();