@usmanaliqureshi The problem seems to be that in toggles_grouped_faqs you are looping through all of the groups rather than filter_array.
If filter_array is empty THEN you can loop through all groups. And as you loop though each group (filer_array or all groups) you can then call the individual group to get the rest of its info if needed…because filer_array won’t have all of that. And just like that your plugin works as expected.
Here is my replacement function. Can I ask that you add this to the next release.
private function toggles_grouped_faqs( $filter_array ) {
if(!empty($filter_array)){
$faq_groups = $filter_array;
}
else {
$faq_groups = get_terms( 'faq-group' );
}
if ( ! empty( $faq_groups ) && ! is_wp_error( $faq_groups ) ) {
foreach ( $faq_groups as $faq_group ) {
if(!isset($faq_group->term_id)){
$faq_group = get_term_by( 'slug', $faq_group, 'faq-group' );
}
$faqs_query = new WP_Query( array(
'post_type' => 'faq',
'posts_per_page' => -1,
'tax_query' => array(
array (
'taxonomy' => 'faq-group',
'field' => 'slug',
'terms' => $faq_group->slug,
)
),
)
);
// FAQs Toggles
if ( $faqs_query->have_posts() ) :
echo '<h4 class="qe-faqs-toggles-group-title">' . $faq_group->name . '</h4>';
echo '<div class="qe-faqs-toggles-group">';
while ( $faqs_query->have_posts() ) :
$faqs_query->the_post();
?>
<div class="nojs qe-faq-toggle active">
<div class="qe-toggle-title">
<strong><i class="fa fa-minus-circle"></i> <?php the_title(); ?></strong>
</div>
<div class="qe-toggle-content">
<?php the_content(); ?>
</div>
</div>
<?php
endwhile;
echo '</div>';
endif;
}
// All the custom loops ends here so reset the query
wp_reset_query();
}
}
-
This reply was modified 5 years, 3 months ago by graftedin.