简体   繁体   English

php get_tags()列出woocommerce中特定类别产品的所有标签

[英]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. 因此,在woocommerce中,当我查看特定类别中的所有产品时,我可以说6页,每页10个产品,或该特定类别中总共60个产品被列出。

I'm using $product->get_tags(); 我正在使用$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(); 问题是$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. 我需要它来获取所有60种产品的所有标签,而不仅仅是第一页上的前十个,或者第二页上的11-20。

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' ); 试试$tags = get_terms( 'product_tag' ); See the function reference at Codex . 请参见Codex上的功能参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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