Support Forum
Hello, I have a problem with the image field, using the example below when editing a post and change any other field and post update the image that is saved in image fields are lost.
function your_prefix_get_meta_box( $meta_boxes ) {
$prefix = 'prefix-';
$meta_boxes[] = array(
'id' => 'untitled',
'title' => esc_html__( 'Untitled Metabox', 'metabox-online-generator' ),
'post_types' => array( 'post', 'page' ),
'context' => 'advanced',
'priority' => 'default',
'autosave' => false,
'fields' => array(
array(
'id' => $prefix . 'text_1',
'type' => 'text',
'name' => esc_html__( 'Text', 'metabox-online-generator' ),
),
array(
'id' => $prefix . 'image_select_2',
'type' => 'image_select',
'name' => esc_html__( 'Image Select', 'metabox-online-generator' ),
'force_delete' => false,
'max_file_uploads' => '4',
),
array(
'id' => $prefix . 'image_4',
'type' => 'image',
'name' => esc_html__( 'Image Upload', 'metabox-online-generator' ),
),
),
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'your_prefix_get_meta_box' );
Complementing, I am using version 4.9 of wordpresss and this only happens with version 4.12.5 of metabox, with version 4.12.4 I do not have the problem presented.
[21-Nov-2017 19:14:07 UTC] PHP Warning: Invalid argument supplied for foreach() in framework\metabox\4.12.5\inc\fields\image-select.php on line 32
[21-Nov-2017 19:14:07 UTC] PHP Stack trace:
Hi, for image_select
field, you need to add options
parameter. Please see this docs.
Hi, thanks for the support. But I am using the field image and not image_select, in the example above was generated by the metabox generator online, I did not see what is missing, can you give me an example of what is missing so that when updating a post I do not lose the already registered image?
Hi,
In the code above, the 2nd field is the image_select
field. If you're using the Online Generator, the please follow this instruction.
You can edit the code of the 2nd field like this:
array(
'id' => $prefix . 'image_select_2',
'type' => 'image_select',
'name' => esc_html__( 'Image Select', 'metabox-online-generator' ),
'options' => array(
'value1' => 'http://urltoyourimage.com',
'value2' => 'http://urltoyourimage.com',
),
),
hello, I think I did not correctly share my problem, I'm not talking about the field 'type' => 'image_select', but the field 'type' => 'image', where updating a post is deleted, this happens when using or metabox 4.12.5.
thank you
Hi, I've fixed this bug on Github. Can you please try it?
PS: My previous reply was for the PHP warning that you posted. Sorry for misunderstanding.
Hello Anh Tran, is working with the update thanks for this.