Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save INDIAN2020/df6f284422acd4b4be1d2cb164bd8f7d to your computer and use it in GitHub Desktop.
Save INDIAN2020/df6f284422acd4b4be1d2cb164bd8f7d to your computer and use it in GitHub Desktop.
add_action( 'pre_get_posts', 'set_posts_per_page' );
function set_posts_per_page( $query ) {
global $wp_the_query;
if ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_search() ) ) {
$query->set( 'posts_per_page', 3 );
}
elseif ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_archive() ) ) {
$query->set( 'posts_per_page', 5 );
}
// Etc..
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment