Support

Account

Home Forums Add-ons Gallery Field Importing external data into a Gallery field

Solved

Importing external data into a Gallery field

  • Hi everyone!

    I’m making a migration from another CMS into WordPress.

    One of the things that I have to migrate are the gallerys (if exists) related to each post.

    The table where I have the data of each picture of the gallery is as follows (Example):

    gallery_table
    id | gallery_id | post_id | filename | position | title
    1 | 1 | 20 | path/01_01.jpg | 1 | title 01_01
    2 | 1 | 20 | path/01_02.jpg | 2 | title 01_02
    3 | 1 | 20 | path/01_03.jpg | 3 | title 01_03
    4 | 2 | 23 | path/02_01.jpg | 1 | title 02_01
    5 | 2 | 23 | path/02_02.jpg | 2 | title 02_02
    6 | 2 | 23 | path/02_03.jpg | 3 | title 02_03
    7 | 2 | 23 | path/02_04.jpg | 4 | title 02_04

    I’m already using the following code for uploading each photo to the media library
    http://www.wpexplorer.com/wordpress-featured-image-url/

    But my question is: How can I import my gallery_table into the Gallery Field of each wordpress post?

    Any suggestions?

    Thanks in advance!

    • Elliot

    • October 2, 2013 at 4:56 pm

    Hi @saavedrajj

    The gallery field expects the value to be saved as an array of attachment ID’s.

    What you will need to do is loop through your images, and use a WP function (check google / WP codex) to insert the attachment. I have done this before, but can’t rember the function name. That function will return you an attachment ID which you can use to then later save an array via the update_field function.

    Hope that helps.

    Thanks
    E

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.