'ASC', 'orderby' => 'title', 'posts_per_page' => -1, 'group' => '', ); // Merge incoming args with the function defaults $args = wp_parse_args( $args, $defaults ); // Container $return = ''; // Get the taxonomy terms assigned to all FAQs $terms = get_terms( 'group' ); // If there are any terms being used, loop through each one to output the relevant FAQ's, else just output all FAQs if( ! empty( $terms ) ) { foreach( $terms as $term ) { // If a user sets a specific group in the params, that's the only one we care about $group = $args['group']; if( isset( $group ) and $group != '' and $term->slug != $group ) continue; // Set up our standard query args. $query_args = array( 'post_type' => 'faq', 'order' => $args['order'], 'orderby' => $args['orderby'], 'posts_per_page' => $args['posts_per_page'], 'tax_query' => array( array( 'taxonomy' => 'group', 'field' => 'slug', 'terms' => array( $term->slug ), 'operator' => 'IN' ) ) ); // New query just for the tax term we're looping through $q = new WP_Query( $query_args ); if( $q->have_posts() ) { $return .= '
' . $term->description . '
'; // Loop through the rest of the posts for the term while( $q->have_posts() ) : $q->the_post(); // Grab our metadata $rtt = get_post_meta( get_the_id(), '_acf_rtt', true ); $lo = get_post_meta( get_the_id(), '_acf_open', true ); // If Open on Load checkbox is true $lo == true ? $lo = ' faq-open' : $lo = ' faq-closed'; // Set up our anchor link $link = 'faq-' . sanitize_title( get_the_title() ); $return .= '