Problems with image type field
- This topic has 7 replies, 2 voices, and was last updated 7 years, 4 months ago by
Infolu Official.
-
AuthorPosts
-
November 22, 2017 at 2:22 AM #7478
Infolu Official
ParticipantHello, 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' );
November 22, 2017 at 3:29 AM #7479Infolu Official
ParticipantComplementing, 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:
November 22, 2017 at 8:51 AM #7486Anh Tran
KeymasterHi, for
image_select
field, you need to addoptions
parameter. Please see this docs.November 22, 2017 at 3:29 PM #7500Infolu Official
ParticipantHi, 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?
November 25, 2017 at 10:19 AM #7582Anh Tran
KeymasterHi,
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', ), ),
November 28, 2017 at 8:50 PM #7679Infolu Official
Participanthello, 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
December 1, 2017 at 9:52 AM #7723Anh Tran
KeymasterHi, 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.
December 1, 2017 at 6:13 PM #7733Infolu Official
ParticipantHello Anh Tran, is working with the update thanks for this.
-
AuthorPosts
- The topic ‘Problems with image type field’ is closed to new replies.