WordPress术语循环,foreach和WP_Qurey作为嵌套循环问题
我已经为常见问题和自定义分类创建了自定义帖子类型,以组织问题和答案 此外,我还创建了一个单页模板,使用下面的代码来显示常见问题解答WordPress术语循环,foreach和WP_Qurey作为嵌套循环问题,wordpress,Wordpress,我已经为常见问题和自定义分类创建了自定义帖子类型,以组织问题和答案 此外,我还创建了一个单页模板,使用下面的代码来显示常见问题解答 $terms = get_terms( 'faq_categories', array( 'orderby' => 'name', 'order' => 'ASC' ) ); foreach($terms as $term) { ?> <h3>&l
$terms = get_terms(
'faq_categories',
array(
'orderby' => 'name',
'order' => 'ASC'
)
);
foreach($terms as $term)
{
?>
<h3><?php echo $term->name; ?></h3>
<?php
$q_args = array(
'post_type' => 'faq',
'tax_query' => array(
'taxonomy' => 'faq_categories',
'field' => 'slug',
'terms' => $term->slug
),
'posts_per_page' => -1
);
wp_reset_postdata();
wp_reset_query();
$ans = new WP_Query($q_args);
while($ans->have_posts())
{
$ans->the_post();
?>
<h5><?php echo the_title(); ?></h5>
<?php
}
}
此外,在wp\U查询循环之前和之后,我尝试了wp\U reset\u postdate()和wp\U reset\u query(),我也尝试过删除它们,但运气不佳
有没有办法解决这个问题
问候
Merianos Nikostax_查询接受数组数组
$q_args = array(
'post_type' => 'faq',
'tax_query' => array(
array(
'taxonomy' => 'faq_categories',
'field' => 'slug',
'terms' => $term->slug
)
),
'posts_per_page' => -1
);
或者重写查询,您实际上不需要税务查询:
$ans = new WP_Query("post_type=faq&faq_categories=$term->slug&posts_per_page=-1");
$ans = new WP_Query("post_type=faq&faq_categories=$term->slug&posts_per_page=-1");