简体   繁体   中英

php get_tags() to list all the tags for the products in a specific category in woocommerce

So in woocommerce when I am looking at all the products in a specific category I have lets say 6 pages of 10 products each or 60 products total in that specific category being listed.

I'm using $product->get_tags(); to get the tags of the products in that category to display them in a sidebar so users can filter through each tag.

The problem is $product->get_tags(); only gets the tags of the products on the current page. I need it to get all the tags from all 60 products, not just the first ten from the first page, or let's say 11-20 on the second page.

Example behavior:

The tags related to all the products in the category are: science, space, mythology, stars

the tags related to the products on the first page are: science, space

echo $product->get_tags(); prints out only science and space.

I need to be able to print out all the tags: science, space, mythology, stars

but pagination is making this limited. Is there another function I could use that I am unaware of? Or maybe a loop?

Try $tags = get_terms( 'product_tag' ); See the function reference at Codex .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM