Images attached to a custom post type
- This topic has 6 replies, 4 voices, and was last updated 3 years, 9 months ago by
Janos.
-
AuthorPosts
-
December 10, 2016 at 11:10 PM #4659
Martin
ParticipantHi Anh,
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.
Martin.
December 12, 2016 at 8:37 AM #4662Anh Tran
KeymasterHi Martin,
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 (withclone
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.
December 12, 2016 at 10:03 AM #4663Martin
ParticipantThanks for the reply, I was looking at the database and I guess that the images are stored the same way.
Old images
New image
Do I need to use a
callback
like the one you posted here?
http://pastebin.com/H7vqqx26Thanks!
December 12, 2016 at 11:52 AM #4664Anh Tran
KeymasterThat seems the way WP stores attachment. I mean the way your old plugin stores images.
The
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.July 21, 2021 at 5:55 PM #29607Janos
ParticipantHello Anh,
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.
Thank you!
July 21, 2021 at 9:42 PM #29618Long Nguyen
ModeratorHi Moga,
You can use the function
rwmb_set_meta()
to set the field value for the fieldimage_advanced
. Get more details on the documentation
https://docs.metabox.io/rwmb-set-meta/
https://docs.metabox.io/fields/image-advanced/#dataJuly 22, 2021 at 2:13 PM #29640Janos
ParticipantThank you!
-
AuthorPosts
- You must be logged in to reply to this topic.