WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Change author that appears in RSS (2 posts)

  1. Scott Bressler
    Member
    Posted 4 years ago #

    I created a user on my blog called "Other Author", as well as a custom field by the same name. If that user is selected as the author of a post, my single.php file is instructed to show the content in the Other Author custom field instead of "Other Author."

    First, is there a better way to credit a post to an author other than those set up as users on my blog than the way I'm currently doing it?

    Second, "Other Author" is still what comes through in the RSS as the creator of the post. How can I filter the RSS to use the custom field instead? I've tried looking through SimplePie some, but I can't figure out what I'd filter.

    Thanks!

    (Might have incorrectly filed this post originally)

  2. Scott Bressler
    Member
    Posted 4 years ago #

    Found this, which is pretty much exactly what I needed.

    For anyone that might find this, my code ended up being:

    /**
     * Filters the_author.
     * If Other Author is the author of a post, changes the author to whatever is in the 'Other Author' custom field for the post, if one exists.
     * Code taken mainly from http://www.wpbeginner.com/wp-tutorials/how-to-rewrite-guest-author-name-with-custom-fields-in-wordpress/
     */
    function fix_other_author( $name ) {
            global $post;
            if ( $name == "Other Author") {
                    $author = get_metadata( 'post', $post->ID, 'Other Author', true );
                    if ( $author != '' )
                            $name = $author;
            }
            return $name;
    }
    add_filter( 'the_author', 'fix_other_author' );
    add_filter( 'get_the_author_display_name', 'fix_other_author' );

Topic Closed

This topic has been closed to new replies.

About this Topic