I have create a custom post type for FAQs and Custom taxonomies to organize the Question & Answers.
Also I have create a single page template to display my FAQs by using the code that following
$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
}
}
My problem is that while I get the question titles, the questions are not grouped by FAQ Categories and under each Category I get all the available questions in repeat.
The result looks like:
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]
Also I have try with wp_reset_postdate() and wp_reset_query() before and after the WP_Query loop, and I have try to remove them too with no luck.
Any idea on how to solve that issue?
Kind regards
Merianos Nikos
tax_query accepts an array of arrays.
Or rewrite your query, you don’t really need a tax_query: