• Resolved twistedsymphony

    (@twistedsymphony)


    I recently started a new wordpress based site, installed v2.3.2 to start and recently upgraded to 2.3.3. I was going to write a custom plugin to do some content management things and started poking around how wordpress handles uploaded images and other files.

    I needed a way to correlate uploaded images with a particular post_id. since the wp_postmeta table has a page_id field I figured it would be a breeze.

    To my surprise each and every uploaded file get’s assigned a unique post_id… so not only do my post and my pages get post_ids but so to all of my uploaded pictures.

    I’ve only made 15 entries into WP between posts and pages but new posts are getting assigned ids in 50s because of all the image files I’ve uploaded.

    It seems quite odd to me that WP would work this way. Is this how it was designed to work and if so why?

    Also is there any way I can automatically associate images with the same post_id for the page they were uploaded to?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Also is there any way I can automatically associate images with the same post_id for the page they were uploaded to?

    Im fairly confident thats how it works out of the box, especially if you uploaded the image(s) while you were making the post(s).

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Is this how it was designed to work and if so why?

    Yes, that is indeed how it is designed.

    Why, well, I have no idea. I disagree with it personally and have complained about it because it offends my sense of database design. However, some of the WordPress developers are fond of using database tables for more than the obvious uses.

    One side effect (or perhaps the whole intention) is that attachments get their own “page” to show them off. So when you put them into a post as a thumbnail, and have it link to “Page”, then you’ll link to a themed page with just that image as the content and the description of it and such. They even get their own page template in the theme: attachment.php.

    Also is there any way I can automatically associate images with the same post_id for the page they were uploaded to?

    Attachment entries in the posts table have a post_parent value set to the post_id that they were initially uploaded for.

    Thread Starter twistedsymphony

    (@twistedsymphony)

    Excellent! thank you Otto42, that was exactly the kind of information I was looking for.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘uploaded files count as new posts’ is closed to new replies.