Skip to content

Instantly share code, notes, and snippets.

@josephhinson
Last active December 29, 2015 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephhinson/7649212 to your computer and use it in GitHub Desktop.
Save josephhinson/7649212 to your computer and use it in GitHub Desktop.
Insert this function into your functions file or plugin in order to filter your post type archive results.
<?php
function my_new_posts_filter($query) {
// in place of "press" put your custom post type -- you can add additional post types by duplicating the if block.
// you can also add more query variables such as 'order'. This is extremely useful
// the is_main_query makes sure you don't indiscriminantly filter secondary loops as well.
if ( !is_admin() && is_post_type_archive('book') && $query->is_main_query() ) {
$query->set( 'posts_per_page', '20' );
}
}
add_action('pre_get_posts','my_new_posts_filter');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment