![](/img/trans.png)
[英]Get all Woocommerce products from current product category term Id in a WP_Query
[英]WP_Query get post by category id returns all categorries
我正在尝试编写一个WP_Query
来检索某个类别中的所有帖子并在博客页面上显示这些帖子。
<?php
$args = array(
'post_status' => 'publish',
'cat' => 24,
'order' => 'DESC'
);
$query = new WP_Query($args);
while ( $query->have_posts() ):
$query->the_post();
get_template_part( 'templates/content/content', 'loop' );
endwhile;
?>
尽管查询只返回降序发布的帖子,但忽略了 category 参数(它返回所有类别的内容循环模板,而不仅仅是类别 24)。
This is the category URL from the admin panel: http://www.apokalipsa.si/wp-admin/term.php?taxonomy=category&tag_ID=24&post_type=post&wp_http_referer=%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dcategory
我尝试用'tag_ID' => 24,
交换'cat' => 24,
查询参数(来自类别页面中的类别 URL)但结果是相同的。
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => 24,
'order' => 'DESC'
);
$query = new WP_Query($args);
while ($query->have_posts()):
$query->the_post();
get_template_part('templates/content/content', 'loop');
endwhile;
你可以试试这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.