I was wondering if someone could help me out. I currently have a custom post type named 'claims-accordion' and a custom taxonomy named 'claims-accordion-type'. I would like to display all 'claims-type' Terms but i would like to also display all the posts that are under that term. I would like to also create a counter that gives the first term title an 'is-active' class.
Here is the code so far:
<?php $_terms = get_terms( array('claim-accordion-type') ); foreach ($_terms as $term) : $term_slug = $term->slug; $_posts = new WP_Query( array( 'post_type' => 'claims_accordion', 'posts_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => 'claim-accordion-type', 'field' => 'slug', 'terms' => $term_slug, ), ), )); if( $_posts->have_posts() ) : echo ''. $term->name .''; while ( $_posts->have_posts() ) : $_posts->the_post(); ?> <h4><?php the_title(); ?></h4> <p><?php get_post_meta( get_the_ID(), 'url', true ); ?></p> <?php endwhile; endif; wp_reset_postdata(); endforeach; ?>
also is it better to use get_posts or wp-Query? I was wondering if someone could help me out i have been trying at this for quite a while and cant seem to get it to work. I appreciate the help.