Show Custom Post Type by Author

You will need to filter ‘author_link’ to conditionally add the parameter that can be used to add the custom post type into the query for the author’s posts.

add_filter( 'author_link', 'myprefix_author_link', 10, 3 );
function myprefix_author_link( $link, $author_id, $author_nicename ) {
    if ( is_singular( 'myCPT' ) || is_post_type_archive( 'myCPT' ) ) {
        $link = add_query_arg( 'post_type', 'myCPT', $link );
    }
    return $link;
}

The default (your else clause) will show only posts anyway, so no new code is needed for that.

Leave a Comment