在本例中,我将使用两种自定义分类法:
酒店所在国家/地区的星级酒店均无等级,那么您的查询将非常简单,例如英国的酒店有两颗星:
$args = array(
\'post_type\' => \'hotel\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'hotel-country\',
\'field\' => \'slug\',
\'terms\' => array( \'uk\' ),
),
array(
\'taxonomy\' => \'stars\',
\'field\' => \'slug\',
\'terms\' => array( \'3-stars\' ),
)
)
);
$query_posts( $args );
更新:使用现有设置,您可以再次使用
\'tax_query\'
但您现在需要子分类id,比如:
UK
3-stars - term_id = 32
那么您的查询和参数应该是:
$args = array(
\'post_type\' => \'hotel\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'Types\',
\'field\' => \'id\',
\'terms\' => array( \'32\' ),
\'operator\' => \'IN\',
)
)
);
$query_posts( $args );
更新2:如果您已经在英国页面,请将代码更改为:
$taxonomy2 = \'accomodation-type\';
//the current page term id, (UK,JAPAN...)
$current_term_id = get_query_var(\'term_id\');
//array of child terms IDs.
$termchildren = get_term_children($current_term_id,$taxonomy2);
$args = array(
\'post_type\' => \'accomodation\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'accomodation-type\',
\'field\' => \'id\',
\'terms\' => $termchildren,
\'operator\' => \'IN\',
)
)
);
$query( $args );
//loop
这将获得所有具有英国住宿类型儿童学期的住宿职位。