Get custom taxonomy terms that contain posts that have another taxonomy term
I have two taxonomies for my property post type:
property-style which has terms for different home styles like Country and Modern, and
property-tag which has terms for amenities such as Swimming Pool and Garage.
On the main page I list all of the property-style terms with the post count:
- Classic [1 Post]
- Country [0 Posts]
- Modern [4 Posts]
- Rustic [3 Posts]
I get these terms by using:
$terms = get_terms( array(
'taxonomy' = 'property-style',
'hide_empty' = false,
'orderby' = 'name',
'order' = 'asc',
) );
On the main page is also a dropdown containing all the property-tag terms, so they can filter the property-style terms, showing only terms that include posts with the selected property-tag term.
So let's say the property-tag dropdown has Swimming Pool selected, and there's only 1 property with a Swimming Pool and it has the property-style of Modern. So now the main page should show:
- Classic [0 Posts]
- Country [0 Posts]
- Modern [1 Post]
- Rustic [0 Posts]
How can I get all the property-style terms, but filtered by property-tag = Swimming Pool?
Topic multi-taxonomy-query terms custom-taxonomy Wordpress
Category Web