Include both default and Custom Post Type in query modified inside pre_get_posts

As Kaiser mentioned, the post_type parameter can accept an array of post types. Updating the function to use is_main_query() to limit the filter to only the “main” query, the code would look like:

add_action( 'pre_get_posts', 'custom_post_author_archive' );
function custom_post_author_archive( $query )
{
    if ( is_main_query() && is_author() )
    {
        set_query_var( 'post_type', array('post','custom_post') );
    }
}

Leave a Comment