Skip to content

Instantly share code, notes, and snippets.

@robneu
Last active January 26, 2021 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robneu/6513742 to your computer and use it in GitHub Desktop.
Save robneu/6513742 to your computer and use it in GitHub Desktop.
Set the number of posts per page in all WordPress category archives using pre_get_posts.
<?php
add_action( 'pre_get_posts', 'prefix_category_query' );
/**
* Customize category query using pre_get_posts.
*
* @author FAT Media <http://youneedfat.com>
* @copyright Copyright (c) 2013, FAT Media, LLC
* @license GPL-2.0+
* @todo Change prefix to theme or plugin prefix
*
*/
function prefix_category_query( $query ) {
if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && is_category() ) {
$query->set( 'posts_per_page', '10' ); //Change this number to anything you like.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment