I would like to know which relationship in the database determines which images are displayed in the media dialog when you select 'images uploaded to post' as the search filter.

I thought it would just be the 'post_parent' column in wp_posts providing that the post type is an attachment and the mime_type is correct, however I have tried this and it does not appear to be working?

This is for rows that I am adding to the posts table dynamically, not through images that I've uploaded using the media manager.


  • 1
    I've just tested this and confirmed that it is the post_parent column. Dec 12, 2014 at 21:34
  • What test did you carry out which confirmed this please? And I will replicate the test and see if I get a similar outcome. Dec 13, 2014 at 14:37

2 Answers 2


Solved it! It was an issue with the Polylang plugin stopping the image from showing, I'm not quite sure why but adding a row to the wp_term_relationships table, where the object_id is the id of the attachment, and the term_taxonomy_id is the id of the language definition in the wp_term_taxonomy table fixed the issue.


It is the post_parent field, actually. So, in order to properly answer your question, we would need to know why you think that is not the case.


Based on your comment, I suspect you also need to set the post_status to "inherit".

Also, the GUID isn't the URL of the file anymore, not since 2.7. That might still actually work, but it is not reliable.

Instead of filling that GUID in, examine the postmeta table for a normally uploaded image, and you will find two rows for the post.

One of these is the _wp_attached_file row, which will have the local path name of the image (from the uploads folder).

The other will be the _wp_attachment_metadata row, which contains a PHP serialized array of the image information. This includes width, height, filename, various sizes of the image that exist, and the image_meta array, which contains data extracted from the image's EXIF information, like shutter speed, iso information, camera model, etc.

To get the image working properly, you will likely need to fill in both of these rows, at least partially. Not all the metadata is actually needed, but the size and filename info is somewhat important.

  • Oops! Sir, pardon me, is that an answer? Dec 13, 2014 at 5:00
  • I have a row in wp_posts which is an image. The post_type = 'attachment', post_mime_type = 'image/jpeg', and the guid points to a valid image file, and the id in post_parent is the id of the post I want it to appear in the 'images uploaded to post' section, so really it can't be? Dec 13, 2014 at 14:05
  • Edited my answer to have more info.
    – Otto
    Dec 14, 2014 at 0:20

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.