最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Get custom taxonomy terms that contain posts that have another taxonomy term

programmeradmin6浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论