nickberens360
2/4/2015 - 2:27 PM

Nested loop display custom taxonomy and associated posts

Nested loop display custom taxonomy and associated posts

<?php

        $taxes = get_terms([
            'taxonomy' => 'menu_item_categories',
            'parent' => 0,
            'hide_empty' => false,
        ]);


        foreach ($taxes as $term) { ?>

            <h3><?= $term->slug; ?></h3>

            <?php
            $args = array(
            	'post_type' => 'menu_items',
            	'menu_item_categories' => $term->slug,
            	'orderby' => 'menu_order title',
            	'order'   => 'ASC',
            );
            $query = new WP_Query( $args );
            ?>
            <?php if($query->have_posts()) : ?>
            	 <?php while($query->have_posts()) : $query->the_post() ?>

            			<p><?php the_title(); ?></p>

            	 <?php endwhile ?>
            <?php endif ?>
            <?php wp_reset_postdata(); ?>

       <?php } ?>