Support Forum
Troubles with single image. In the documentation:
https://docs.metabox.io/fields/single-image/
The documentation: I can use the helper function rwmb_meta() and this return an array of image information. However I am trying but the helper function only return an string with the ID of attachment.
array (
'id' => $prefix . 'if_vehiculos_imagen2',
'type' => 'single_image',
'name' => esc_html__( 'Imagen principal', 'text-domain' ),
'tab' => 'if_vehiculos_tab_general',
),
In my functions.php
$query = new WP_Query(array(
'post_type' => 'vehiculo',
'post_status' => 'publish',
'posts_per_page' => -1,
));
while ($query->have_posts()) {
$imagen = rwmb_meta('if_vehiculos_imagen2', array( 'size' => 'miniatura' ),$post_id );
var_dump($imagen);
}
Full PHP code https://pastebin.com/KqXVBy7E
Hi,
Please see my screen record https://www.loom.com/share/9d172996936742d9803a0321e62366c7.
When you get the field single_image
value by the helper function rwmb_meta()
, it returns an array of the image as well.
You can check again with this code
$imagen = rwmb_meta( 'if_vehiculos_imagen2', array( 'size' => 'thumbnail' ), $query->post->ID );
Sorry but it don't work for me. The helper is returning a string with the ID of attschment.
Hi,
Here is my sample code to get the single_image
field's information via custom query
$query = new WP_Query(array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 10,
));
while ($query->have_posts()) {
$query->the_post();
$image = rwmb_meta( 'post_meta_single_image', array( 'size' => 'thumbnail' ) );
echo '<a href="', $image['full_url'], '"><img src="', $image['url'], '"></a><br>';
echo "<pre>";
print_r($image);
echo "</pre>";
}
and a screen record demonstrates https://www.loom.com/share/d31c328cc0654b10ad4aeed977e23900.
Could you please take some screenshots of a screen record of this issue? I will take a closer look and give a quick response.
Use your code to reproduce the issue, but it still works as well https://www.loom.com/share/9a7c2daf36d34d9683ffd09f7b69d11e.
Hello, I really appreciate your time. Very good support. It still doesn't work for me. I don't know if it's because I'm using this code in my functions.php
but I have to do the following:
$imagen = rwmb_meta('if_vehiculos_imagen', array( 'size' => 'full' ));
$full = (wp_get_attachment_image_src($imagen,'full'));
I checked that metabox definition was before this code. Some idea for solved it?
Hi,
Please make sure that you are using Meta Box v5.3.3, deactivate all plugins except Meta Box and MB extensions, switch to the default theme of WordPress (Twenty Twenty) then check the issue again.
If it still shows only image ID, please follow this guide to know how to create the staging site https://www.wpbeginner.com/wp-tutorials/how-to-create-staging-environment-for-a-wordpress-site/.
Then share the credentials (Admin site and FTP account) via this form https://metabox.io/contact/. I will check it out.
I'm having the same problem, except it's with Image Advanced, with multiple images saved to the post. Not only does it only return an ID instead of an array of stuff, it only returns ONE ID, even if there's more than one pic saved to that post.
I've turned off all non-MB plugins, switched the theme to Twenty Twenty, and it's still happening.
I confirmed in the database that all three images exist for that post in wp_post_meta.
Since I turned off my plugin that defined the CPT that has the Image Advanced, the way I declared the field doesn't matter (it wasn't in a group, though).
Here is what I put in a template file - putting in the post ID of the CPT post that has the images, since that CPT doesn't exist right now, but it still returns a single integer, matching one of the 'meta_value' fields of the images I put on the post.
var_dump(rwmb_meta('product_gallery', array('size' => 'full'), '345'));
This gives me
string(3) "525"
output on the page.
Thank you for any help you can provide!