I frequently see Page templates like this when someone’s trying to create a custom loop – possibly inspired by the built-in functionality of creating a Page as a stub for Posts when another Page is set as the front page for the site. That’s a special case, and not what people should be doing.
Instead of using a Page template and running a second query in place of the content, what you should be doing is creating taxonomy-custom_taxonomy.php
and altering the default WP_Query
before it’s sent to the DB by hooking pre_get_posts
to get the result you want. Here’s the sort of function you’d want in your child theme’s functions.php:
add_action( 'pre_get_posts', 'wpse281501_taxonomy_query' );
function wpse281501_taxonomy_query($query) {
if($query->is_main_query() && $query->is_tax( 'custom_taxonomy' ) {
$query->set( 'posts_per_page', 4 );
}
}
Taxonomy archives support pagination by default, whereas a Page template requires kludging support in because Pages aren’t paginated.
If you’re only looking to apply this layout to a specific term within the taxonomy you’d need to call your template taxonomy-custom_taxonomy-custom_term.php
and pass the term as the second argument to is_tax()
in your hooked function:
if($query->is_main_query() && $query->is_tax( 'custom_taxonomy', 'custom_term' )