Skip to content

Instantly share code, notes, and snippets.

@j-cam
Last active August 29, 2015 14:19
Show Gist options
  • Save j-cam/e12b30ce1311e0e60e62 to your computer and use it in GitHub Desktop.
Save j-cam/e12b30ce1311e0e60e62 to your computer and use it in GitHub Desktop.
Wordpress: Disable Infinite Scroll for custom post type archives and set posts_per_page
if ( ! function_exists( 'cpt_archives_settings' ) ) :
add_action( 'pre_get_posts', 'themename_cpt_archives_settings' );
// Pass the $query argument into the action.
function themename_cpt_archives_settings( $query ) {
// Define the context.
// Not on dashboard pages when inside the main query only on cpt archives.
if( ! is_admin() && $query->is_main_query() && is_post_type_archive( 'cpt_name_goes_here' ) ) {
// remove infinite scroll inside this context
remove_theme_support( 'infinite-scroll' );
// set query vars for this context
$query->set( 'posts_per_page', '-1' );
}
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment