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

woocommerce offtopic - Categories on attribute archive pages

programmeradmin5浏览0评论

I have Wordpress + Woocommerce site setup with about ~2k products. Products have several different attributes like "Brand" and attribute values for "Brand" like "Samsung", "Philips" etc.

On "Brand" archive page like "Samsung Archives" I want to show menu of product categories containing products with that attribute. ("Samsung products") Others I don't want to show.

I guess one way would be to query all products in category loop, then query for attributes and depending on result show/hide this category on menu. The problem is that this method can impact performance if archive page is visited a lot and/or category tree is big.

Probably someone knows better approach for this and wants to share with it?

I have Wordpress + Woocommerce site setup with about ~2k products. Products have several different attributes like "Brand" and attribute values for "Brand" like "Samsung", "Philips" etc.

On "Brand" archive page like "Samsung Archives" I want to show menu of product categories containing products with that attribute. ("Samsung products") Others I don't want to show.

I guess one way would be to query all products in category loop, then query for attributes and depending on result show/hide this category on menu. The problem is that this method can impact performance if archive page is visited a lot and/or category tree is big.

Probably someone knows better approach for this and wants to share with it?

Share Improve this question asked Nov 21, 2020 at 22:30 John DoeJohn Doe 1 1
  • How is brand stored in the database? I'd guess it's just a postmeta value or a taxonomy, and you can query for posts by that. – Rup Commented Nov 22, 2020 at 1:42
Add a comment  | 

1 Answer 1

Reset to default 0

OK, if any body come across this question I managed to find better and workable solution.

Before querying all the categories on sidebar I check if this is brand archive page and if yes I use wp_get_object_terms function, pass all product ids from wp query to get only needed categories. :)

In this way I show only categories which have products that have queried brand term.

发布评论

评论列表(0)

  1. 暂无评论