使用WP_Query
使用tax_query
和ameta_query
参数,并仅返回ID以节省一点服务器资源。
$args = array(
\'post_type\' => \'post\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'people\',
\'field\' => \'slug\',
\'terms\' => \'bob\',
),
),
\'meta_query\' => array(
array(
\'key\' => \'age\',
\'value\' => array( 3, 4 ),
\'compare\' => \'IN\',
),
),
\'fields\' => \'ids\'.
);
$query = new WP_Query( $args );
并检查
found_posts
元素
$query
--
var_dump($query->found_posts);