Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Eric

    (@eklemen2)

    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: https://www.example.com/author/john-doe guest author ex: https://www.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;
    
    }
    Thread Starter Eric

    (@eklemen2)

    I ended up going with the Co-Authors Plus plugin. It still was a bit challenging, but this plugin achieved all that I needed to: https://www.ads-software.com/plugins/co-authors-plus/

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Guest Author – How to display posts on /author archive page’ is closed to new replies.