Custom taxonomy template loop

The way I read you question is that you need 12 posts per page in this taxonomy regardless of the current term been displayed.

This can be easily done with pre_get_posts. You should never change the main query for a custom query on archive pages. Have a read on this answer I’ve recently done on this subject.

Use the is_tax() conditional to target the taxonomy page and also see the parameters

Add this to functions.php. You can also only use one taxonomy.php for all terms, no need to make 50 others

function custom_ppp( $query ) {
    if ( !is_admin() && $query->is_tax() && $query->is_main_query() ) {
        $query->set( 'posts_per_page', '12' );
    }
}
add_action( 'pre_get_posts', 'custom_ppp' );

EDIT

In taxonomy.php, change this

<?php $loop = new WP_Query( array( 'post_type' => 'all_products', 'pre_get_posts' => 12, 'products' => 'advance' ) ); ?> 

<?php while ( $loop->have_posts() ) : $loop->the_post(); ?> 
    //content 
<?php endwhile; ?>

back to just this

<?php while ( have_posts() ) : the_post(); ?> 
   //content
<?php endwhile; ?>

Leave a Comment