admin管理员组文章数量:1410717
On a page like taxonomy-product_cat.php - this function lists just the products for the called sub-category - bags:
$args = array( 'post_type' => 'product', 'product_cat' => 'bags')
$loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post();
I can hardcode list all the sub-categories and then dynamically list the products. I want to dynamically create the subcategory list with the associated products listed with it - what is the best way to do this? I am thinking that if I make the 'product_cat' => dynamic - is a way to achieve this?
On a page like taxonomy-product_cat.php - this function lists just the products for the called sub-category - bags:
$args = array( 'post_type' => 'product', 'product_cat' => 'bags')
$loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post();
I can hardcode list all the sub-categories and then dynamically list the products. I want to dynamically create the subcategory list with the associated products listed with it - what is the best way to do this? I am thinking that if I make the 'product_cat' => dynamic - is a way to achieve this?
Share Improve this question edited Jan 26, 2020 at 12:19 Jon asked Jan 22, 2020 at 14:52 JonJon 3652 gold badges8 silver badges24 bronze badges 1- do you mean the actual category of the category archive page, or a sub-category of that actual category? in what file are you using that code? – Michael Commented Jan 23, 2020 at 20:15
2 Answers
Reset to default 1You shouldn't be using WP_Query
at all. The standard loop will automatically display the correct posts.
while ( have_posts() ) : the_post();
endwhile;
You can use get_queried_object()
, within that object you can get the slug
or id
.
本文标签: wp queryWhat code to use in an array to call the current subcategory
版权声明:本文标题:wp query - What code to use in an array to call the current sub-category? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744803713a2626015.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论