我为常见问题解答和自定义分类法创建了一个自定义帖子类型来组织问答。
我还创建了一个单页模板,使用以下代码显示我的常见问题解答
$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
}
}
我的问题是,当我得到问题标题时,这些问题没有按常见问题类别分组,并且在每个类别下,我都会重复获得所有可用的问题。
结果如下所示:
Sale [FAQ Category]
How to buy? [FAQ Question]
What is the cost? [FAQ Question]
How can I contact you? [FAQ Question]
What is your address? [FAQ Question]
Contacts [FAQ Category]
How to buy? [FAQ Question]
What is the cost? [FAQ Question]
How can I contact you? [FAQ Question]
What is your address? [FAQ Question]
此外,我在 WP_Query 循环之前和之后尝试使用wp_reset_postdate()和wp_reset_query(),并且我也尝试将它们删除但没有运气。
关于如何解决该问题的任何想法?
亲切的问候梅里亚诺斯尼科斯