Last active
August 29, 2015 14:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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