Skip to content

Instantly share code, notes, and snippets.

@bherrero
Last active August 8, 2018 06:52
Show Gist options
  • Save bherrero/94231b8469592448e7d24df4243e6e29 to your computer and use it in GitHub Desktop.
Save bherrero/94231b8469592448e7d24df4243e6e29 to your computer and use it in GitHub Desktop.
Get all the posts for a CPT archive
// pre_get_posts to get all the posts por the CPT Archive
add_action( 'pre_get_posts', 'pre_get_posts_archive_custom_cpt' );
function pre_get_posts_archive_custom_cpt( $query ) {
if( is_admin() ) {
return;
}
if ( $query->is_post_type_archive( 'custom_cpt_name' ) && $query->is_main_query() ) {
$query->set( 'posts_per_page', -1 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment