Skip to content

Instantly share code, notes, and snippets.

@bananadesign
Last active August 12, 2020 11:36
Show Gist options
  • Save bananadesign/e5e9e3bd3ebe884b5c54a4a6373525e0 to your computer and use it in GitHub Desktop.
Save bananadesign/e5e9e3bd3ebe884b5c54a4a6373525e0 to your computer and use it in GitHub Desktop.
<?pjp
function banana__query_modifications($query) {
if ($query->is_main_query() && get_query_var('post_type') == 'faqs') {
$query->set('posts_per_page', -1);
$query->set('orderby', 'taxonomy');
$query->set('order', 'DESC');
}
/* if ($query->is_main_query() && $query->is_tax()) {
$query->set('orderby', 'title');
$query->set('order', 'ASC');
} */
}
add_action('pre_get_posts', 'banana__query_modifications');
?>
<ul class="faqs accordion">
<?php $cat_name = null; while (have_posts()) : the_post(); ?>
<?php $terms = get_the_terms($post->ID, 'categories');
if ($terms && !is_wp_error($terms)) :
if ($cat_name != $terms[0]->name) :
$cat_name = $terms[0]->name; ?>
<h2><?php echo $cat_name; ?></h2>
<?php endif; ?>
<?php endif; ?>
<li id="faq-<?php the_ID(); ?>">
<h3><?php the_title(); ?></h3>
<div class="answer"><?php the_field('answer'); ?></div>
</li>
<?php endwhile; ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment