Import images into custom table
Support › MB Custom Table › Import images into custom tableResolved
- This topic has 2 replies, 2 voices, and was last updated 4 years, 9 months ago by
rebecmari.
-
AuthorPosts
-
July 31, 2020 at 10:24 PM #21079
rebecmari
ParticipantHello!
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:
- 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)?
- 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!
August 1, 2020 at 9:07 AM #21090Long Nguyen
ModeratorHi,
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 storedhttp://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 tablewp_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 liketext
to store the image URL.
- Modify the CSV file, change the link of the image to the formathttp://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/August 6, 2020 at 11:36 PM #21157rebecmari
ParticipantHi 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.
-
AuthorPosts
- You must be logged in to reply to this topic.