I created my own template for list of entries for certain tag (tag.php), It will shows up 10 entries, and with Previous & Next link.

$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'post_type'     => 'custom_post',
'posts_per_page' => '10',
'tag'           => "$some_tag",
'paged'         => "$paged",
'post_status'   => 'publish',
'orderby'       => 'date',
'order'         => 'ASC'

$loop = new WP_Query($args);
while($loop->have_posts()): $loop->the_post();
// displaying items here
<nav id="page-nav">
    <?php previous_posts_link('≪ Previous', $loop->max_num_pages); ?>
    <?php next_posts_link('More ≫', $loop->max_num_pages); ?>
<?php endif; ?>

It creates a More link with /tag/ta_name/page/2 but when i click on it, it shows 404.

I've checked on other blogs, tag archives pagination indeed ends with /page/N so i guess there is no problem with my url.

Where did i make the mistake or any of my settings is wrong?

1 Answer 1


The current page number is set by the main query, not by your embedded sub-query. Also, you really should not create a second query, alter the main query instead with a filter on pre_get_posts.

add_filter( 'pre_get_posts', 'add_custom_type_to_tag_archive' );

function add_custom_type_to_tag_archive( $query )
    if ( ! is_main_query() or ! is_tag() )
        return $query;

    $query->set( 'post_type', array ( 'custom_type', 'post' ) );
    $query->set( 'posts_per_page', 10 );

    return $query;


When WordPress loads your tag.php it has already queried the database for tags. It knows already what tag it is, what post type and how many results there are in total and for the current page.
This is too late to change the pagination. And you should not waste that query, because it takes time.

So do not try to overwrite the main query later, alter the main query instead to get faster, more reliable results.

  • the 404 is probably caused from not having enough "normal" posts for that tag Jun 14, 2017 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.