Archive page of CPT's custom Taxonomy

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

Topic archive-template custom-post-type-archives custom-taxonomy custom-post-types Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.