最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Display custom post type category, while in a CPT category, then the posts beneath

programmeradmin1浏览0评论

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();
}
发布评论

评论列表(0)

  1. 暂无评论