Custom Fields
Re-Envisioned
Support MB Custom Table Import images into custom table

  • Creator
    Topic
  • #21079
    rebecmari
    Participant

    Hello!

    I am working on re-creating a records database using MB Custom Table. The original database was from a custom site (not WordPress), and I have a CSV export of all the data from the original SQL database.

    I have created a custom post type for the records and am able to all save data from custom fields into the database. From the tests I have done, I am able to import most of the existing data into the site through the SQL database, so that part is working great. However, I am having trouble figuring out how to import the images affiliated with each record, since they are serialized in the database.

    In the CSV of data from the original site, the image file name is listed for each record. For example: ‘2429.JPG’. Originally, I was thinking I could add this data, upload the images to WordPress, and then build the url in the WordPress structure (i.e. ‘/wp-content/uploads/2020/07/’ + ‘2429.JPG’) to display the images. From a backend approach, I think I could make this work (even though it is a bit hackish), but going forward I was planning to have the images uploaded through the Meta Box image field, which serializes the data…so I am back to square one. A couple of questions:

    1. Is there a way that I can import the images from the original database into the custom table (without manually uploading and entering all of them)?
    2. Thinking about longevity, if I ever need to export this database to be used outside of WordPress, would I be able to extract the file name out of the serialized image data? If so, how?

    I do primarily front-end dev, so I am not very knowledgable on a lot of this database work. Everything with your plugins so far has been straightforward to use for my skill level in helping to set this up. Appreciate any insight you can give to point me in the right direction!

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #21090
    Long Nguyen
    Moderator

    Hi,

    Let’s dive a bit into the WordPress core and you will know how it stores the image information.

    • Each image after uploading to the Media Library is a post with the post type attachment. You will have the image ID and a link where the image stored http://your-site.com/wp-content/uploads/year/month/image-name.extension.
    • Meta Box image fields image, image_advanced, image_upload save the ID of the image (post ID attachment) into the database. It does the same as Featured Image of WP core, save the image ID in the table wp_postmeta with meta key _thumbnail_id.

    So in your case, I think you can do some steps:
    – Upload all images through Media Library.
    – Create a simple custom field like text to store the image URL.
    – Modify the CSV file, change the link of the image to the format http://your-site.com/wp-content/uploads/year/month/image-name.extension.
    – Import post meta through the CSV file with this plugin https://wordpress.org/plugins/wp-ultimate-csv-importer/.

    If you want to export the database to use outside of WordPress, you can use a third-party plugin to export the file. It will help you export the information you want to have in the file export.
    https://wordpress.org/plugins/wp-ultimate-exporter/
    https://wordpress.org/plugins/wp-all-export/

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.