Create guest author page via php

Custom fields don’t have an archive template so you may wish to consider using a custom taxnomy, where the terms are the names of your guest authors.

I think this is quicker and easier than messing around with custom templates on pages, less code wrangling and complexity.

Naturally if you have lots of posts with your custom guest meta data attached to them already, this is going to be a bit of a pain to switch things over. If however you’re in the early stages of implementation i’d encourage you to use a taxonomy instead because you’ll get archive view functionality baked in (in the same way you do with categories).

Registering a custom taxonomy can be done manually with code, like so (adjust as desired).

function wpse410299_register_my_taxes() {
    /**
     * Taxonomy: Guest Authors.
     */
    $labels = [
        "name" => esc_html__( "Guest Authors", "twentytwentytwo" ),
        "singular_name" => esc_html__( "Guest Author", "twentytwentytwo" ),
    ];
    
    $args = [
        "label" => esc_html__( "Guest Authors", "twentytwentytwo" ),
        "labels" => $labels,
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => true,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => [ 'slug' => 'guest_author', 'with_front' => true, ],
        "show_admin_column" => false,
        "show_in_rest" => true,
        "show_tagcloud" => false,
        "rest_base" => "guest_author",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "rest_namespace" => "wp/v2",
        "show_in_quick_edit" => false,
        "sort" => false,
        "show_in_graphql" => false,
    ];
    register_taxonomy( "guest_author", [ "post" ], $args );
}
add_action( 'init', 'wpse410299_register_my_taxes' );

Or if you prefer less code management and want a simple dashboard interface for creating taxonomies and post types, i’d recommend Custom Post Type UI, i actually used it to create test data and the code above(saved me a bunch of time).

Add some terms under the Guest Author taxonomy which you can do whilst you edit/create posts and select an appropriate Guest Author. You will now have the ability to use taxonomy views to list out posts by your “guest” authors by querying yoursite/guest_author/name/ or click the view link under the term(guest author) on your Guest Authors taxonomy page in the admin. If you’re thinking the guest_author portion of the URL looks awful, use something nicer looking in the rewrite portion of the taxonomy.

Should you want to still make use of your original author rewrite filter it would only require a small change to call wp_get_post_terms instead of get_post_meta. Unlike get_post_meta there’s no single value return, but you can have it return a simple array of names which will cover both a single term and multi term result if we call implode, so in the event there’s a case where you’ve attached two or more guest authors to a post it will become a comma separated string and still look tidy, and just flatten to a simple non comma separated value otherwise.

$author = wp_get_post_terms( $post->ID, 'guest_author', array( 'fields' => 'names' ) );
$author = implode( ', ', $author );

Hope that helps.

For your follow-up request:

add_filter( 'author_link', 'change_author_to_term' );

function change_author_to_term( $link ) {
    global $post;
    $guest = get_the_terms($post->ID,'guest_author');
    if( !$guest )
        return $link;
    return get_term_link($guest[0]->term_id);
}