Support Forum
Support › Meta Box Builder › retrieving image in post from new fieldResolved
Hi, I have purchased meta box builder and I have added file upload as a new file and it works fine, however im using the grid template builder with WPbakery page builder and I have added a custom field and in the input I have tried adding both the ID of the new metafield and also this shortcode [rwmb_meta id="single_image_ngobiqx24ya"] but neither seem to be pulling the image from the new field, are you able to advise? thank you.
Hi Steve,
WPBakery is a premium plugin so I've not checked the shortcode with this builder before. Please share a copy of this plugin via the contact form https://metabox.io/contact/, I will test the shortcode on my end.
FYI, I also test the shortcode with Elementor and it works as well.
Hi Long, Thanks for getting back to me. I cannot send you the plugin as this is art of a theme bundle, i can send you the login credentials though so you can try yourself, I tried adding the shortcode directly to the page but nothing is displaying. Is it possible to send a private reply on here with the login details?
Also just to mention the field type I added is "single image" im not sure if this makes a difference to my shortcode?
Hi,
This is a public forum so you should share the login credentials via this form https://metabox.io/contact/.
Thanks Long I just sent the login details via the contact form, please confirm receipt of this information.
Got the issue. You've added the prefix for the field ID, screenshot https://share.getcloudapp.com/DOuodQb7.
So the field ID when using the shortcode is flipimagesingle_image_ngobiqx24ya
. Get more details in the tab Code of Field Groups.
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
function your_prefix_register_meta_boxes( $meta_boxes ) {
$prefix = 'flipimage';
$meta_boxes[] = [
'title' => esc_html__( 'Flip Image', 'text-domain' ),
'id' => 'flip-image',
'post_types' => ['post', 'portfolio'],
'context' => 'side',
'priority' => 'low',
'fields' => [
[
'id' => $prefix . 'single_image_ngobiqx24ya', //here
'type' => 'single_image',
'name' => esc_html__( 'Single Image', 'text-domain' ),
],
],
];
return $meta_boxes;
}
Thank you! where did you add this function code as I will be happy to just remove the prefix to make it easier.
Hi,
The PHP code is generated by the Builder, you can share it with other sites that do not have the MB Builder extension. And I've checked the code to see the settings of the meta box and custom fields. You can learn to use it in the documentation https://docs.metabox.io/extensions/meta-box-builder/#getting-php-code.
Hi Long, how can I pass the post ID to the shortcode dynamically so the grid can associate the correct post ID in each shortcode/post?
Hi Long, I hope you’re well. are you able to get back to me on the last message?
Hi,
I also receive your message via the ticket system so I will reply here and close the ticket.
If you are building a grid template and want to include the shortcode to show the custom field of a post, you have to pass the fixed post ID as the object_id
value.
[rwmb_meta id="field_id" object_id="15"]
Hi Long please do not close the ticket as it is not complete and not solved.
As I mentioned it is not possible to write the fixed post ID in the grid builder because the grid serves multiple posts within the same grid design, lets say 10 posts are shown through the same grid so for this to work the objectID must be passed through in the same way like the field ID is in the shortcode, do you see what I mean?
Hi Steve,
Let me explain more about your case.
So in the grid, you have to insert 10 shortcodes with the object_id
(portfolio ID) to show each portfolio such as:
[rwmb_meta id="single_image" object_id="1"]
[rwmb_meta id="single_image" object_id="3"]
[rwmb_meta id="single_image" object_id="12"]
If not insert the object_id
the shortcode will take the ID of the page (Drink) to pass to the shortcode and show the field value but the page does not have the field value.
Get more details in the documentation https://docs.metabox.io/shortcode/.
object_id The object ID. Optional. If not defined, then the current object ID is used
Hi Long, this is not possible the grid will be showing hundreds of different portfolio items, my client needs to be able to add new portfolio items and they display through the grid design, we cannot add a new shortcode every time they wish to add a new site,, this is not realistic, even if we have to add a new metafielcd called post ID, is it not possible to automatically refill this field with the post id/objectID?
A second option is using the grid builder custom fields which is currently working and this is displaying the correct records and fields for each item, the text fields all display fine but when I add the custom key for the image field rather than it showing the image it just shows numbers instead? how can we fix this? on the below link you will see the data is displaying correctly in the first white box but if you look for the numbers on this page (9596) this should be the image displaying: shorturl.at/cjIW3