The WP_Query class will automatically AND
any filters that are set. In your case, using $query->set( 'meta_query', ... )
means that WordPress will be looking for posts from the current author (because this is the author template) AND that have your custom meta key. From my understanding of your problem, this intentionally will never happen, so the query can’t be modified this way.
Instead, you’ll need the posts_where filter to add an OR
condition to the WHERE
clause:
function wp_75068_filter_where( $where ) {
if ( is_author() ) {
global $wpdb;
$co_author_posts = get_posts( array(
'numberposts' => 99,
'meta_key' => 'writer',
'meta_value' => 'the same author name',
'fields' => 'ids' // fetch only the IDs
) );
if ( ! empty( $co_author_posts ) ) {
$where .= " OR $wpdb->posts.ID IN (" . implode( ", ", array_map( 'intval', $co_author_posts ) ) . ") ";
}
}
return $where;
}
add_filter( 'posts_where', 'wp_75068_filter_where' );
Code hasn’t been tested, so let me know if there are any hiccups!