I have a registered Taxonomy called Types, which is hierarchical and works.
An example of categories will be
Hotel in UK
–1 star
–2 star
–3 star
Hotel in Spain
–1 star
–2 star
–3 star
etc..
I m having trouble finding the right way to display my pages (custom post Hotel).
I need the code to display hotels by taxonomy only if they exist
any help?
UPDATE CODE
$taxonomy2 = 'accomodation-type';
$termsacc = get_terms("accomodation-type",array('orderby' => 'slug', 'order' => 'ASC'));
foreach ($termsacc as $termaccomodation) {
//Here I loop through my tax acc-type
//and check if there is any post by the country $termcountry->name (getting this value higher)
$query = new WP_Query(array('post_type' => 'accomodation', 'orderby'=> $termaccomodation->name,'order' => 'DESC','accomodation-type' =>$termaccomodation->name, 'country' =>$termcountry->name,'posts_per_page' => 48 ));
and loop....
I would use in this case two custom taxonomies:
both none-hierarchical then your query would be as simple as for example hotel in uk with 2 stars:
Update:
Using your existing setup you can once again use
'tax_query'
but you will need to now the child-taxonomy id, say:then your query and args should be:
Update 2:
If you are already in the UK page then change you code to this:
this will get all posts of accomodation that have a accomodation-type child term of UK.