Skip to content

Instantly share code, notes, and snippets.

@yanknudtskov
Created February 4, 2014 10:54
Show Gist options
  • Save yanknudtskov/8801602 to your computer and use it in GitHub Desktop.
Save yanknudtskov/8801602 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