Guest Author – How to display posts on /author/ archive page

I have used the Advanced Custom Fields plugin to create all the data elements for a company leadership directory page and management bio pages.

On the site blog, management will not be posting articles themselves, but it should appear as if they have. I think this practice is referred to as “guest authors” – authors that don’t have user accounts in the WordPress site where the content is posted on their behalf by site admins.

What I’d like to happen is this:

  1. When a guest author is selected for the post (an ACF Custom Post Object), output their name. The name should link to the archive page www.example.com/author/john-doe.
  2. When a quest author is not selected, default to the site admin’s author info.
  3. I do NOT want to create ghost user accounts to post as guest authors. (As mentioned, these guest authors have already been defined in detail as part of the team leadership post type in combination with ACF.)

I’m relatively new to WordPress theme development and have been Googling for a way to achieve this. These two posts are the closest I could find to my situation but do not solve what I’m trying to do:

  • Guest Author – How can I use custom fields to create guest author link?
  • Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?

Is this a common practice? If so, can someone direct me to more information? I’d greatly appreciate it!

UPDATE

I’m kinda getting there. So far I’ve managed to write a custom author posts link if a guest author exists.

The resulting URL for a post author and guest author now have matching formats …

post author ex: www(dot)example.com/author/john-doe
guest author ex: www(dot)example.com/author/jane-doe

Now I just need to figure out how to hijack the author archive page
to display posts from the post author OR the guest author.

FUNCTIONS.PHP CODE:

add_filter( 'the_author_posts_link', 'custom_author_posts_link' );

function custom_author_posts_link($url) {

`global $post;

$post_object = get_field('post_author');

if ( $post_object ) {

`// GUEST AUTHOR EXISTS - override post object to grab relevant guest author info
global $post;
$post = $post_object;
setup_postdata( $post );

$guest_author_slug = $post->post_name;
$guest_author_name = get_field('team_member_name');
$guest_author_posts_link = site_url() . '/author/' .  $guest_author_slug;

$guest_url = sprintf(
    '<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
    esc_url( $guest_author_posts_link ),
    esc_attr( sprintf( __( 'Posts by %s' ), $guest_author_name ) ),
    $guest_author_name
);

$guest_url = $link; 

wp_reset_postdata(); // We're done here. Return to main $post object
`

}

return $url;
`

}

UPDATE 2

I’ve reworked things a bit. Instead of ‘hijacking’ the author archive page, I’ve modified the “the_author_posts_link” filter to point to a custom post type, when it’s appropriate to do so. Now each of my three author types has an endpoint where I can display their bio and activity.

The blog posts use Advanced Custom Fields which have a select pulling in post objects from the two relevant post types, Team Leadership and Guest Contributors.

add_filter( 'the_author_posts_link', 'custom_author_posts_link' );

function custom_author_posts_link($url) {

    global $post;

    // Check if a post author is defined in the post_author post object. If none is defined, override will     not occur and default post author will display    
    $post_object = get_field('post_author');    

    if ( $post_object ) {

        // Post author exists. Override post object to grab relevant guest author info.
        global $post;
        $post = $post_object;
        setup_postdata( $post );

        $author_type = get_field('author_type');
        $author_slug = $post->post_name;
        $author_name = get_field('author_name');

        // Use the post author type to determine the author link 
        if ( strtolower($author_type) == 'guest contributor' ){
            $author_posts_link = site_url() . '/guest-contributor/' .  $author_slug;
        } else {
            $author_posts_link = site_url() . '/leadership-team/' .  $author_slug;
        }

        // Format the link to return. This is based off the default filter (See WordPress: https://core.trac.    wordpress.org/browser/tags/4.1/src/wp-includes/author-template.php)    
        $guest_url = sprintf(    
            '<a href="%1$s" tit    le="%2$s" rel="author">%3$s</a>',    
            esc_url( $author_po    sts_link ),    
            esc_attr( sprintf(     __( 'Posts     by %s' ), $author_name ) ),    
            $author_name    
        );    

        $url = $guest_url; 

        wp_reset_postdata(); // We're done here, return to main $post object

    }

    return $url;

}

Solutions Collecting From Web of "Guest Author – How to display posts on /author/ archive page"

You could have saved yourself a ton of work and just used the Co-Authors Plus plugin. It has a guest author function. You do have to set them up, but there is no account/password for them, and they can have author pages. (I am not affiliated with them, just use it on several sites.)

If you want something to behave like a “normal” wordpress author then the best thing to do is to create a “dummy” account for it, and if you really want disable the possibility to login to it.
For any other solution that mimics the functionality in other ways you first need to fully understand the functionality you are trying to mimic, and by your own words “I’m relatively new to WordPress theme development”….