Support Forum
Support › MB Custom Table › Import images into custom tableResolved
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:
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!
Hi,
Let's dive a bit into the WordPress core and you will know how it stores the image information.
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
.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/
Hi Long,
Thanks for the reply! This worked great. I combined your suggestion with the MetaBox File Input field (instead of text), so future images can also be selected from the Media library, and it will list their url in the database.