Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm doing some customization on a theme that was previously written by someone else. Rather than use multiple user accounts to assign articles, they created a taxonomy for the custom author name(s) so that an archive of posts by an author can be generated. The code is below, and it's working well. However, I'd also like to replace the author name in the feed. I assume it's going to be an extra filter and/or function. Can someone help me out?

add_filter( 'the_author_posts_link', 'custom_author_name' );
add_filter( 'get_the_author_display_name', 'custom_author_name' );
function custom_author_name( $name ) {
    global $post;
    $author = get_the_terms(get_the_ID(),'article_author');
    if ( $author )
        $name = the_terms(get_the_ID(),'article_author','',' & ');
    return $name;
}

Update. I tried adding this function, based on code found elsewhere on stack exchange, but it seems to be overwriting the author on the whole site, not just the feed:

add_filter( 'the_author', 'feed_author' );
function feed_author($name) {
  if( is_feed() ) {
    global $post;
    $author = get_the_terms(get_the_ID(),'article_author');
     if ( $author )
         $name = the_terms(get_the_ID(),'article_author','',' & ');
     return $name;  
  }
}

Figured it out!

Ended up using this modified from the sample get_the_terms code in the WP Codex.

add_filter( 'the_author', 'feed_author' );
function feed_author($article_authors) {
    if( is_feed() ) {
       $author = get_the_terms( get_the_ID(), 'article_author' );
       if ( $author && ! is_wp_error( $author ) ) {  
           $byline = array();
           foreach ( $author as $author ) {
           $byline[] = $author->name;
           }   
           $article_authors = join( " & ", $byline );   
       }    
       return $article_authors;
    }
}
share|improve this question
    
try adding add_filter( 'the_author', 'custom_author_name' ); –  Bainternet Oct 4 '11 at 16:33
    
Wouldn't that mess with the actual author/editor/user functionality in the dashboard. I don't want to change the author so much as I want to be able to change who is listed as the author on the site and in the feed. –  John Chandler Oct 4 '11 at 17:14
    
I guest it would, so just wrap it inside a conditional check , something like: if (is_feed()){...} –  Bainternet Oct 4 '11 at 17:30
    
I added the function above, but it seems to be overwriting the author name for all the posts, not just in the feed. –  John Chandler Oct 4 '11 at 20:31
    
John, where is the answer you promised? :) –  toscho Jul 16 '12 at 23:41

1 Answer 1

try this:

add_filter( 'the_author', 'feed_author' );
function feed_author($name) {
    if( is_feed() && !is_admin()) {
        global $post;
        $author = get_the_terms($post->ID,'article_author');
        if ( $author )
            $name = the_terms($post->ID,'article_author','',' & ');
        return $name;  
    }
}
share|improve this answer
    
Thanks. I figured it out with some different code, which I'll post shortly. This one returned an error, but I didn't troubleshoot since I had worked it out. –  John Chandler Oct 4 '11 at 23:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.