Skip to content

Instantly share code, notes, and snippets.

@codehooligans
Last active August 29, 2015 14:08
Show Gist options
  • Save codehooligans/d5f9877a742fe236220e to your computer and use it in GitHub Desktop.
Save codehooligans/d5f9877a742fe236220e to your computer and use it in GitHub Desktop.
Codehooligans.com: Limit Posts per Archive Page
function limit_posts_per_archive_page( $query ) {
// If running within wp_admin or NOT the main $wp_query abort!
if ( is_admin() || ! $query->is_main_query() ) return;
if ( $query->is_category() ) {
$query->set('posts_per_archive_page', 8);
} elseif ( $query->is_search() ) {
$query->set('posts_per_archive_page', 10);
}
}
add_action('pre_get_posts', 'limit_posts_per_archive_page');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment