[wp-hackers] Placing a guest author custom field

Dion Hulse (dd32) wordpress at dd32.id.au
Mon Apr 4 01:12:17 UTC 2011


If you include the add_filter +   guest_author_name code in your themes
functions.php file, you shouldn't have to change the_author() to
get_post_meta()...

The way the filter code works, if is you have assigned a guest name, it
overrides the output of the_author() to that of the guest, otherwise
displays the "normal" author name.

On 4 April 2011 11:07, RePost <repost_08 at yahoo.com> wrote:

> 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.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list