要在查询搜索中添加“类别名称”或“类别ID”,必须应用内部联接(wp\\U term\\U关系)。
请试试这个
$category\\u id是您的类别id
<?php
$args = array(
\'post_type\' => \'post\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'color\',
\'value\' => \'red\',
\'compare\' => \'=\'
),
array(
\'key\' => \'size\',
\'compare\' => \'EXISTS\'
)
),
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'category\',
\'field\' => \'id\',
\'terms\' => $category_id,
\'operator\' => \'IN\'
)),
);
$query = new WP_Query( $args );
?>