Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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/

    Thread Starter Eric

    (@eklemen2)

    Through trial and error, I discovered the foreach loop was not needed on author.php archive page. A little more streamlined than my last comment.

    $this_author_display_name = get_the_author();
    if( get_the_author_meta( 'guest_author_title' ) ){
    	// account authors
    	$this_author_title = get_the_author_meta( 'guest_author_title' );
    } elseif( get_post_meta( $authorID, 'guest_author_title', true ) ){
    	// CAP guest author
    	$this_author_title = get_post_meta( $authorID, 'guest_author_title', true );
    }
    if( get_the_author_meta( 'email' ) ){
    	$this_author_email = get_the_author_meta( 'email' );
    }
    if( get_the_author_meta( 'guest_author_phone_number' ) ){
    	// account authors
    	$this_author_phone_number = get_the_author_meta( 'guest_author_phone_number' );
    } elseif( get_post_meta( $authorID, 'guest_author_phone_number', true ) ){
    	// CAP guest authors
    	$this_author_phone_number = get_post_meta( $authorID, 'guest_author_phone_number', true );
    }
    if( get_the_author_meta( 'guest_author_linkedin' ) ){
    	// account authors
    	$this_author_linkedin = get_the_author_meta( 'guest_author_linkedin' );
    } elseif( get_post_meta( $authorID, 'guest_author_linkedin', true ) ){
    	// CAP guest authors
    	$this_author_linkedin = get_post_meta( $authorID, 'guest_author_linkedin', true );
    }
    if( get_the_author_meta( 'guest_author_twitter' ) ){
    	// account authors
    	$this_author_twitter = get_the_author_meta( 'guest_author_twitter' );
    } elseif( get_post_meta( $authorID, 'guest_author_twitter', true ) ){
    	// CAP guest authors
    	$this_author_twitter = get_post_meta( $authorID, 'guest_author_twitter', true );
    }
    if( get_the_author_meta( 'description' ) ){
    	$this_author_description = get_the_author_meta( 'description' );
    }
    Thread Starter Eric

    (@eklemen2)

    P.S. This is what I ended up doing to the time being. It feels dirty. Is there a better way?

    // If there's a cleaner way to do this, I haven't found out how. The author data seems to be accessed differently for account-holding authors and non-account co-authors (created by co-authors plus plugin) when using custom fields (created by Advanced Custom Fields).
    
    // Default all author values to null
    $this_author_display_name = $this_author_title = $this_author_email = $this_author_phone_number = $this_author_linkedin = $this_author_twitter = $this_author_biography = null;
    
    // Co-Authors (non custom fields also return for account-holding authors)
    $coauthors = get_coauthors();
    foreach( $coauthors as $coauthor ){
    	$this_author_display_name = get_the_author();
    	if( get_post_meta( $coauthor->ID, 'guest_author_title', true ) ){
    		$this_author_title = get_post_meta( $coauthor->ID, 'guest_author_title', true );
    	}
    	if( $coauthor->user_email ){
    		$this_author_email = $coauthor->user_email;
    	}
    	if( get_post_meta( $coauthor->ID, 'guest_author_phone_number', true ) ){
    		$this_author_phone_number = get_post_meta( $coauthor->ID, 'guest_author_phone_number', true );
    	}
    	if( get_post_meta( $coauthor->ID, 'guest_author_linkedin', true ) ){
    		$this_author_linkedin = get_post_meta( $coauthor->ID, 'guest_author_linkedin', true );
    	}
    	if( get_post_meta( $coauthor->ID, 'guest_author_twitter', true ) ){
    		$this_author_twitter = get_post_meta( $coauthor->ID, 'guest_author_twitter', true );
    	}
    	if( $coauthor->description ){
    		$this_author_biography = $coauthor->description;
    	}
    
    }
    
    // Account Holding Authors (custom fields)
    if( get_the_author_meta( 'guest_author_title' ) ){
    	$this_author_title = get_the_author_meta( 'guest_author_title' );
    }
    if( get_the_author_meta( 'guest_author_phone_number' ) ){
    	$this_author_phone_number = get_the_author_meta( 'guest_author_phone_number' );
    }
    if( get_the_author_meta( 'guest_author_linkedin' ) ){
    	$this_author_linkedin = get_the_author_meta( 'guest_author_linkedin' );
    }
    if( get_the_author_meta( 'guest_author_twitter' ) ){
    	$this_author_twitter = get_the_author_meta( 'guest_author_twitter' );
    }
    Thread Starter Eric

    (@eklemen2)

    P.S. What I’m trying to do is create a custom author.php page that displays the same info for post authors (account holders) as co-authors (non-account holders).

    Thanks again!

    This is not working for me.

    On my author.php using Jeremy’s example above, I get the following results:

    $coauthors = get_coauthors();
    foreach( $coauthors as $coauthor ){
    	$userdata = get_userdata( $coauthor->ID );
    	var_dump( $userdata ); //returns bool(false)
    	if ( $userdata->display_name ) { //returns "Notice: Trying to get property of non-object"
    		echo '<h2>' . $userdata->display_name . '</h2>';
    	}
    }

    Any ideas what I’m doing wrong?

    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 discovered my error wasn’t in the loop itself, but in how I was calling the function. Here’s how I correctly called the function:

    <?php
    $upcoming_events = the_merged_presentation_events(true);
    if( $upcoming_events !== false ){
    	echo '<h3>Upcoming Presentations</h3>';
    	echo $upcoming_events;
    }
    >
    Thread Starter Eric

    (@eklemen2)

Viewing 8 replies - 1 through 8 (of 8 total)