Skip to content

Instantly share code, notes, and snippets.

@caseymhunt
Last active December 16, 2015 00:29
Show Gist options
  • Select an option

  • Save caseymhunt/5347570 to your computer and use it in GitHub Desktop.

Select an option

Save caseymhunt/5347570 to your computer and use it in GitHub Desktop.
A wordpress functions.php code snippet that overrides the user controlled post limit so that certain post types or pages will display all or a declared number of posts rather than obey this limit.
<? // Open tag added for proper color formatting- DO NOT COPY THIS LINE
// Function to override the set value of Post Limit in Wordpress
function theme_post_override ( $query ) {
// Only act on author pages
if ( is_author() ) {
// Display ALL posts
$query->set( 'posts_per_page', -1 );
return;
}
// Act on 'custom' post type when displaying archive of posts
if ( is_post_type_archive(' custom' ) ) {
// Display 10 posts
$query->set( 'posts_per_page', 10 );
}
}
add_action( 'pre_get_posts', 'theme_post_override', 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment