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 have multiple author accounts on one of my WordPress installs. Often I will create a post, and set the author to be a different account. However, when I upload images into that post, their attachment page lists the author as my account. How can I set the author for posts, and have it carry over to the media associated with that post?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Use this in your theme's functions.php:

add_filter( 'add_attachment', 'wpse_55801_attachment_author' );

function wpse_55801_attachment_author( $attachment_ID ) 
{
    $attach = get_post( $attachment_ID );
    $parent = get_post( $attach->post_parent );

    $the_post = array();
    $the_post['ID'] = $attachment_ID;
    $the_post['post_author'] = $parent->post_author;

    wp_update_post( $the_post );
}
share|improve this answer
    
Thanks! Will this only work for new posts? I added the filter to my functions.php but it seems that it won't be applied to existing posts / attachments. Is there a way to do that? –  Ryan Jun 25 '12 at 18:42
    
Actually, after adding, it doesn't seem to be working on new posts either. –  Ryan Jun 25 '12 at 18:48
1  
@Ryan . Well, I did test before publishing... Re-tested now with WP 3.4 & TwentyEleven 1.4 & Custom Post Type, and another with WP 3.1 & TwentyTen 1.2 & normal Post... Works on both... Can you test in a clean WP install? :::: For updating old posts, couple one of these solutions with my code. –  brasofilo Jun 25 '12 at 20:58
add comment

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.