Display posts the match taxonomy term linked from wp_list_categoies?

Steve, you’ve asked a couple of questions which I had a look at, and I came to the conclusion that your loop is causing all of your headaches.

My loop to display ALL the posts is:

$args = array( 'post_type' => 'design_asset', 'posts_per_page' => 100, 'orderby' => 'title', 'order' => 'ASC'  );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();

Custom loops on any archive page creates problems. The main query is quite specific on these pages, and these queries are a shlep to reproduce in a custom query. To get an idea how the main query works and how the main query decides what to show where, go and check my answer on this question

I would advice you against using any custom query for your primary loop on any archive page, or even the home page.

My advice would be to change all your loops in all your templates back to the default loop

if ( have_posts() ) :
    while ( have_posts() ) : the_post();

       <----LOOP ELEMENTS---->

     endwhile;
 endif;

After you’ve changed back to the default loop, you’ll see that everything will work normally, except your custom post type will not be included in your main loop.

To rectify this, you will use pre_get_posts to add your custom post type and other modification to the main query

function include_cpt( $query ) {
    if ( !is_admin() && $query->is_main_query() ) {
        $query->set( 'post_type', 'design_asset' );
        $query->set( 'posts_per_page', '100' );
        $query->set( 'orderby', 'title' );
        $query->set( 'order', 'ASC' ); 
    }
}
add_action( 'pre_get_posts', 'include_cpt' );

This should have everything working normal and as expected

Leave a Comment