这是对Display Post by taxonomy and taxonomy child if exist
我需要显示住宿列表,首先按住宿类型,然后按地区。我有一个帖子类型,叫做accomodation
, 分类法Country
, 分类法accomodation-type
, 分类法Region
我在国家/地区页面中,通过以下方式检索国家/地区的价值
$taxonomy = \'country\';
$terms=get_the_terms($post->ID,$taxonomy);
if($terms) {
foreach( $terms as $termcountry ) {
所以我成功地$termcountry->name;
作为当前国家的价值。接下来,我需要根据该国家/地区查询住宿,并按住宿类型和该类型中的地区进行过滤。应该是这样的
Acc类型1,区域1,Acco 1,Acco 2,Acc类型2,等等
$taxonomy2 = \'accomodation-type\';
$termsacc = get_terms("accomodation-type",array(\'orderby\' => \'slug\', \'order\' => \'ASC\'));
//Loop through Acc-Type
foreach ($termsacc as $termaccomodation) {
//Loop through Region in this type
$taxonomyregion = \'region\';
$termsreg = get_terms("region",array(\'orderby\' => \'slug\', \'order\' => \'ASC\'));
foreach ($termsreg as $termregion) {
$args = array(
\'post_type\' => \'accomodation\',
\'country\' => $termcountry->name,
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'accomodation-type\',
\'field\' => \'slug\',
\'terms\' => array($termaccomodation->name),
),
array(
\'taxonomy\' => \'region\',
\'field\' => \'slug\',
\'terms\' => array($termregion->name),
)
)
);
$query = new WP_Query($arg);
//Do the loop
但这并没有做到。。。。这件事让我挠头,我会提前感谢您的帮助/解决方案THX