• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2784

Original Genesis Tutorials & 6000+ Guaranteed Code

Snippets

  • Consultation
  • Full Access
  • Log in

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.

pre_get_posts

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags