This is a follow up to Display Post by taxonomy and taxonomy child if exist
I need to display a list of Accomodation, first by Type of Accomodation, then by Regions.
I have a post-type, called accomodation
, a taxonomy Country
, a taxonomy accomodation-type
, a taxonomy Region
I am in the Country page, where I retrieve the value of the country via
$taxonomy = 'country';
$terms=get_the_terms($post->ID,$taxonomy);
if($terms) {
foreach( $terms as $termcountry ) {
So I am successfully getting $termcountry->name;
as the value of current country.
Next I need to do my query for the Accomodation based on that country, filtered by Accomodation Type, and by region in this type. So it should be
- Acc-Type 1
- Region1
- Acco 1
- Acco 2
- Acco 3
- Region 2
- Acco 1
- Acco 2
- Region1
- Acc-Type 2
- etc....
I am trying to do it this way
$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
but this is not doing it.... Scratching my head proper on this one and will appreciate some help/solution thx in advance