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

advanced taxonomy queries - get terms hiding empty

programmeradmin3浏览0评论

I have different taxonomies, let's say category and colour, these 2 tax have different terms, the tax are in parallel, a product can be in the category A and have colours X, in my frontend when I go in the page for the category A I show all the products in the category A, in this page I also show all the colours as filter, I'd like to hide all the colour that are not present in any product in the category A.

Here an example that should help understand my issue:

Product 1:

  • category: car
  • color: red

Product 2:

  • category: car
  • color: black

Product 3:

  • category: bike
  • color: purple

if I go in the page of category "car" and I do something like:

get_terms('colours', array(
  'hide_empty' => true
))

I'm able to see purple, even if in this category there are no product with colour purple, that make sense because WP check the total count for that particular taxonomy but I would like to find a way to get the colour only for the products in the category A

so:

get_terms('colours', array(
  'hide_empty' => true
))

should returns only ["red", "black"]

many thanks

发布评论

评论列表(0)

  1. 暂无评论