• Hi everybody,
    I’m trying to create a post by ajax request then set attachments to its gallery. Basically this should be in two steps:
    1. Create a post with gallery format.
    2. Set attachments to its gallery.

    Let’s just say i already know the attachment ID’s.
    How do i do this?

    Thank you!
    Josef.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I would start by hooking the filter ‘wp_insert_post_data’ so I can analyze the contents of the passed array when I manually publish a gallery post with attachments. You would then replicate this structure with code. Then you simply $wpdb->insert the array to the post table. Probably should run it through stripslashes_deep() first though.

    If I may guess where you’re going with this, the ajax component has more to do with the attached images than the gallery format. If so, you might consider creating a static gallery style framework, which would use ajax to place imagery. This way the database remains unaffected.

    Thread Starter joymanur

    (@joymanur)

    Hi bcworkz,
    thanks for your suggestion. I already analyzed the relationship between a gallery of a post and its gallery images. Unfortunately it’s a one to one relationship for an image to post, so an image can only be included to one gallery and only once.

    I guess i have to do this with another way.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘create post then set attachments to its gallery?’ is closed to new replies.