我有一个自定义的post类型“packages”,具有多种分类法;i、 e.“目的地”
i、 e.mysite。com/目的地/新西兰/
post类型“packages”还有其他分类法,即“难点”
我希望过滤这些区域页面;类似于:mysite。com/目的地/新西兰/?难度=中等
以下是WP\\U查询:
$term_id = "12"; //medium
$taxquery = array(
\'posts_per_page\' => 1,
\'post_type\' => \'packages\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'difficulty\',
\'field\' => \'term_id\',
\'terms\' => $term_id,
\'operator\'=> \'IN\'
))
);
最合适的回答,由SO网友:TrubinE 整理而成
// 12 - difficulty
// destination
// get Id current taxonomy
$this_term = get_queried_object();
$taxquery = array(
\'posts_per_page\' => 1,
\'post_type\' => \'packages\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'difficulty\',
\'field\' => \'id\',
\'terms\' => array( 12 ),
),
array(
\'taxonomy\' => \'destination\',
\'field\' => \'id\',
\'terms\' => array( $this_term->term_id) // Id current taxonomy
)
)
);