0

Working on a project with a lot of galleries & "attachment" post type queries. It's all working great except I noticed in the Attachment Details box in the admin dashboard that Wordpress stores & displays the attachment upload author & uploaded to post. So the question - does anybody have experience or know how to return the upload author & uploaded to post ID within the loop of a custom attachment query?

I've searched through the codex and stackexchange but haven't been able to come up with anything.

Thanks!

1
  • Can you post your attachment query?
    – Howdy_McGee
    Apr 27, 2015 at 20:05

2 Answers 2

0

Attachments count as a built-in post type which is extremely similar to Posts and Pages. The field you're looking for is post_author.

If you have an attachment object:

$attachment->post_author

If you only have the attachment ID you can use

get_post_field( $attachment_id, 'post_author );

To get the actual Post the the attachment was originally uploaded to you can use:

$post->post_parent
0

Thanks to @howdy_mcgee for the first answer! I actually was on that track as he was posting. To answer the second part of my question of getting the uploaded to post_id, that is equivalent to the post parent which I grabbed simply with get_post( $post->post_parent );

Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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