bherrero
9/29/2017 - 6:59 PM

Get all the posts for a CPT archive

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 );   
    }
}