[wp-hackers] Placing a guest author custom field

RePost repost_08 at yahoo.com
Mon Apr 4 01:07:58 UTC 2011


I'm trying to place a Guest Author field (as described at 
wpbeginners.com) in my index.php and single.php templates. I inserted 
some code in functions.php:

|// guest author custom field
add_filter( 'the_author', 'guest_author_name' );
add_filter( 'get_the_author_display_name', 'guest_author_name' );

function guest_author_name( $name ) {
global $post;

$author = get_post_meta( $post->ID, 'guest-author', true );

if ( $author )
$name = $author;

return $name;
}|


I edited my index.php and single.php templates to replace this:

|<?php the_author();?>|


with this:

|<?phpechoget_post_meta($post->ID,'guest-author',true);?>
|

This works fine when I select the custom field and fill in a guest 
author's name. But if I don't use a custom field because I'm publishing 
my own post, the author's name is left blank on the blog!

What am I missing here?

Thanks.


More information about the wp-hackers mailing list