Home Forums General Issues update image field with image from the wordpress media library Reply To: update image field with image from the wordpress media library

  • If you have the name or url of the image, that is fine, use this function to reverse query the url to get the attachment id.

    and here was my explanation and solution

    I had the same issue on a past project where there were about 11,000 images, i knew the names of the images that came from the old system for a custom post, but i didnt know the new id when they were all in wordpress (i spent 2 hours manually uploading the images to know everything went through as i had issues with automated upload).

    And this was a gallery of images for each post, so i did the following:

    1. connected to old db and batch processed 200 posts from the old system at a time (with a start value and stop value for IDS of their old system posts), loading their custom image gallery
    2. fed them into an relational array with the SKUID of their system as a key identifier – you end up with a massive relational array of SKUID and array of images in each array slot.
    3. loaded the wordpress load.php
    4. repeat through the array to get the custom SKUID of the post
    5. load the wp post with corresponding skuid (ACF text field)
    6. foreach loop on the images in the initial array with the correct SKUID
    7. fed the image name with a prepended string for the wp-content folder
    8. gave me back the correct id so i could then insert it in to another array
    9. when ending the foreach loop i then assigned the array to the gallery field.

    this script was run on the root of the wordpress installation and removed when finished.