I'm trying to list custom post type categories, then the posts beneath them that are contained in that category. This will be on a parent category page.
It should look like:
To-Go (Parent Category and current page)
Description of parent category or whatever information is loaded into the category description field.
Breakfast
Description of this category or whatever information is loaded into the category description field.
Item 1
Item 2
Appetizers To Go
Description of this category or whatever information is loaded into the category description field.
Item 1
Item 2
All I've managed to do is show every post in that custom post type including posts not in the "to go" category. How can I get this to limit?
My code:
$cat_args = array (
'taxonomy' => 'menus-category',
'tag_ID' => 54,
'menus-category' => 'to-go'
);
$categories = get_categories ( $cat_args );
foreach ( $categories as $category ) {
$cat_query = null;
$args = array (
'post_type' => 'newmenus',
'post_status' => 'publish',
'order' => 'ASC',
'orderby' => 'date',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'menus-category',
'terms' => array( $category->slug ),
'field' => 'slug',
'menus-category' => 'to-go'
)
)
);
$cat_query = new WP_Query( $args );
if ( $cat_query->have_posts() ) {
echo "<h3 class='entry-title'>". $category->name ."</h3>"; ?>
<div id="items">
<?php
while ( $cat_query->have_posts() ) {
$cat_query->the_post();
?>
<div>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header>
<?php the_title( '<h3 class="entry-title to-go-items" itemprop="name">', '</h3>' ); ?>
</header><!-- .entry-header -->
<div class="entry-content">
<span itemprop="description"><?php the_content(); ?></span>
<div class="to-go-menu-price" itemprop="price" itemscope itemtype=""><?php the_field('price'); ?></div>
</div><!-- .entry-content -->
<span class="menu-price">
<?php echo esc_html( get_post_meta( get_the_ID(), 'nova_price', true ) ); ?>
</span>
</article>
</div>
<?php
}
echo "</div>";
}
wp_reset_postdata();
}