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

Archive page of CPT's custom Taxonomy

programmeradmin1浏览0评论

I have a Custom Post Type: "Sponsors"

Sponsors have a Custom Taxonomy: "Sponsor Ranks" Sponsor Ranks are divided like Platinum Sponsors - Gold Sponsors - Silver Sponsors and so on

I want to make an archive page that will show me all sponsors within their respected rank

Currently I have something that works perfectly fine but I am unsure if this is the right way. I am basically making a new query every time, that doesn't feel right.

    <div class="row">
        <?php
            $args = array(
                'post_type' => 'dev_sponsors',
                'tax_query' => array(
                'relation' => 'AND',
                    array(
                        'taxonomy' => 'sponsor_ranks',
                        'field' => 'slug',
                        'terms' => array( 'platinum-sponsors' )
                    )
                )
            );
            $query = new WP_Query( $args );     
        ?>
        Platinum Sponsors:<br />
        <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
            <?php $img = get_the_post_thumbnail(get_the_ID(), 'gold'); ?>
            <div class="col-3">
            <?php echo $img; ?><br />
            <?php echo $post->post_title; ?>    
            </div>
         <?php endwhile; 
         wp_reset_postdata();           
         endif; ?>          
    </div>      
    <div class="row">
        <?php
            $args = array(
                'post_type' => 'dev_sponsors',
                'tax_query' => array(
                'relation' => 'AND',
                    array(
                        'taxonomy' => 'sponsor_ranks',
                        'field' => 'slug',
                        'terms' => array( 'gold-sponsors' )
                    )
                )
            );
            $query = new WP_Query( $args );     
        ?>
        Gold Sponsors:<br />
        <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
            <?php $img = get_the_post_thumbnail(get_the_ID(), 'gold'); ?>
            <div class="col-3">
            <?php echo $img; ?><br />
            <?php echo $post->post_title; ?>    
            </div>
         <?php endwhile; 
         wp_reset_postdata();           
         endif; ?>          
    </div>
发布评论

评论列表(0)

  1. 暂无评论