I have question related to the attachments.
In my case I have a website for used cars and when I built it, years ago, I used a plugin to let my client post from the front-end.
This plugin is no longer working with the latest version of WordPress, I removed this old plugin and I installed the Meta Box plugin.
This old plugin created some custom fields for brand, model, color and other stuff. With meta box I was able to retrieve that information. But I'm wasn't able to get the images for each post.
I was looking at this solution you provided here and using an image field but is not working.
Here you can see a screenshot of the Meta Box working with the custom fields, another meta box with empty images, and the attachments of the post.
What I'm trying to achieve is to put the images in any of the image uploaders available so that my client can later add more images or removed them.
Thanks and let me know if you have any questions for me.
That depends on how you store the images in the post meta. With Meta Box, image IDs are saved in the post meta (each image ID is saved a meta key). You can read more about that here.
If the old plugin saves image IDs in the post meta in the same way as Meta Box, then Meta Box can show them without problem.
But if it saves image URLs in the post meta, then you might want to use the field
file_input instead (with
clone parameter enabled if you have multiple images).
And in the worst case, you can write a script to migrate the old data to the new format compatible with Meta Box.
Thanks for the reply, I was looking at the database and I guess that the images are stored the same way.
Do I need to use a
callback like the one you posted here?
That seems the way WP stores attachment. I mean the way your old plugin stores images.
callback you mentioned in another topic is used to **display** the images only. It doesn't help add/remove more images in the custom fields.
I have a question related to this topic, or at least similar.
I have more than 3000 posts (products), and I would like to attach images to the posts. I uploaded the images (more than 40,000) to the Media Library. I have already made a field in the custom post type (Image Advanced).
How could I attach images to the Image Advanced field without manually adding them? I tried WP All Import, but it doesn't work.
You can use the function
rwmb_set_meta() to set the field value for the field
image_advanced. Get more details on the documentation