Problems with image type field

Support General Problems with image type field

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #7478
    Infolu OfficialInfolu Official
    Participant

    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' );
    #7479
    Infolu OfficialInfolu Official
    Participant

    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:

    #7486
    Anh TranAnh Tran
    Keymaster

    Hi, for image_select field, you need to add options parameter. Please see this docs.

    #7500
    Infolu OfficialInfolu Official
    Participant

    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?

    #7582
    Anh TranAnh Tran
    Keymaster

    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',
        ),
    ),
    #7679
    Infolu OfficialInfolu Official
    Participant

    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

    #7723
    Anh TranAnh Tran
    Keymaster

    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.

    #7733
    Infolu OfficialInfolu Official
    Participant

    Hello Anh Tran, is working with the update thanks for this.

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Problems with image type field’ is closed to new replies.