Set Posts Per Page For Tag Archive

This code enables you to set the posts per page limit for any tag archive page. This way you can over ride the WordPress > Reading settings which effect all archive page types.

The following code only executes on the tag archive page with a slug tag-one. Replace tag-one with the slug or i.d of your tag.

add_action('pre_get_posts', 'posts_per_tag_archive_page');

function posts_per_tag_archive_page( $query ){
if ( $query->is_tag('tag-one') ) {
    $query->set( 'posts_per_page', 1 );
    return;
    }
}

The following code effects all tag archive pages:

add_action('pre_get_posts', 'posts_per_tag_archive_page');

function posts_per_tag_archive_page( $query ){
if ( $query->is_tag() ) {
    $query->set( 'posts_per_page', 1 );
    }
}

This enables you to display pagination on your tag archives.

The code uses the is_tag conditional tag with pre_get_posts.

Was This Tutorial Helpful?

Free

$0

Access only to all free tutorials per month.



Monthly

$75

Access to 10 premium tutorials per month.


Tutorial Request


Includes code guarantee and coding support.

Yearly

$500

Access to 15 premium tutorials per month.


Monthly Tutorial Request


Includes code guarantee and priority coding support.