1

I have Woocommerce shop with several product categories, custom taxonomies and ACF meta fields. So one product has one category, terms of taxonomies and meta fields values.

For example, we have categories "Washing machines" and "Fridges" and taxonomy "Brand" with terms "Siemens", "Bosch". On product page with specific category or specific category page I need to show terms of taxonomy "Brand", that have products in this specific category. So, on every page I should check the current category and list only nesessary taxonomy terms.

Meta fields are configured to show only in one product category, so we can say, that one ACF field is attached to one category. But taxonomies are attached to the whole post type.

So, the problem is how to quickly get the terms of taxonomy from posts that have specific term of another taxonomy? I can get posts by special query like that

$args = array(
'post_type' => array('post','reviews'),
'paged' => $paged,
'tax_query' => array(
  array(
    'taxonomy' => 'category',
    'terms' => 'android',
    'field' => 'slug'
  ),
  array(
    'taxonomy' => 'review_category',
    'terms' => 'android',
    'field' => 'slug'
  ),
)
);
query_posts($args);

But I can't do this query on every page load. Is there an easier way to solve the problem?

1
  • To clarify, a category is a taxonomy. Taxonomy just means a classification. For the sake of simplification, WP comes installed with 2 main taxonomies; Category (category) and Tag (post_tag). In your case do you have multiple custom taxonomies such as "product category" and "brand"?
    – darrinb
    Apr 12, 2016 at 13:52

0