WordPress.org

Support

Support » Plugins and Hacks » Parent ID of image in wp_posts table not updated?

Parent ID of image in wp_posts table not updated?

  • Hi all,

    When I add a new image to the Media Library, its data gets inserted into wp_posts table, and that seems fine.

    When I use that image for the first time, in the sense that I insert it into a post, its parent ID gets updated to the post ID, and this seems fine as well.

    However, when I afterwards try to insert this same image into a new post, using Media Library (and not by uploading it again), its parent ID doesn’t get updated!

    My question is: is this behavior expected?

    This effects using get_children() and get_posts() for the purpose of getting a list of all attached images.

    Thanks,

    Haris

Viewing 7 replies - 1 through 7 (of 7 total)
  • esmi

    @esmi

    Forum Moderator

    when I afterwards try to insert this same image into a new post, using Media Library (and not by uploading it again), its parent ID doesn’t get updated!

    That’s the correct (as in “expected”) behaviour. If an image is not attached to a Post or Page when it is uploaded (by uploading through Add Media) or attached to a post manually, it is automatically attached to the first post that uses it. Once that attachment is set, it isn’t updated.

    That was a pronto answer, thanks!

    So, having this in mind, there’s not really any part of WP API I can use to get all images in a post? (One of the solutions is examining its content, but I wonder if there’s any function maybe already doing it.)

    esmi

    @esmi

    Forum Moderator

    You can currently only get all images attached to a given Post or Page. As you implied, the content of each Post/Page could be parsed looking for img tags but, as this is going to be very intensive (and therefore have performance implications) I don’t see it being added to WordPress core any time soon.

    Again, thanks.(Y)

    How much sense would it make for WP to:

    a) store a list of parent IDs for an image, or:
    b) store a new record each time an image is inserted?

    esmi

    @esmi

    Forum Moderator

    It might make sense for you but it’s not a request I’ve seen that often (if at all). Because of WP’s market, it’s only the really popular feature requests that get added to core. anything less popular is deemed to be plugin territory.

    You could have a look around and see if there’s a plugin out there that does this for you. There’s also nothing to stop you pitching this on http://wordpress.org/extend/ideas/ – if it hasn’t already been suggested.

    That’s exactly and everything I wanted to know about this at the moment.

    Thanks a lot for the great and quick answers, thumbs up!

    esmi

    @esmi

    Forum Moderator

    Glad I could help 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Parent ID of image in wp_posts table not updated?’ is closed to new replies.
Skip to toolbar