Last active
January 26, 2021 09:05
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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