- This topic is empty.
-
AuthorPosts
-
January 27, 2015 at 7:49 am #194339eklemenParticipant
I figure this is a common WordPress scenario, but I’m having a rough time finding suggestion solutions on the web …
The site I’m developing has guest authors that do not have accounts. The editor will simply choose the guest author and posting on their behalf.
For blog posts, the author link should display the guest author’s name and link to the author archive page. By default, WordPress will do this for the post author. I need to override this behavior when a guest author exists.
I’m stumped.
I’m using Advanced Custom Fields to define the guest authors. When creating a blog post, a ACF post object choose the author.
I believe this has something to do with the the_author, and the_author_posts_link filters as well as modifying the author template.
Any guidance is greatly appreciated!
Thanks!January 27, 2015 at 10:27 am #194354eklemenParticipantUPDATE:
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: http://www.example.com/author/john-doe
guest author ex: http://www.example.com/author/jane-doeNow 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; ` }
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.