• Resolved tom.durcak

    (@freshmaker)


    I tried to create basic Yes/No selection, but I don’t want to have selected any option on begining, to don’t save (or create new) post_meta (when value is empty). So I added an empty option, but it always primary set ‘No’ as checked after load ‘add new’ admin page. Looks like value ‘0’ have some kind of priority to be selected.
    My code:

    $box->add_field( array(
    	'name' => __( 'Selection', 'txtdmn' ),
    	'id' => $prefix . 'selection',
    	'type' => 'radio',
    	'options' => array(
    		'' => __( 'None', 'txtdmn' ), // I want this to be checked
    		'0' => __( 'No', 'txtdmn' ), // this is checked on render
    		'1' => __( 'Yes', 'txtdmn' ),
    	),
    ) );

    I changed values to ‘no’ and ‘yes’, so option with empty value is now selected primary, but I want to use ‘0’ and ‘1’ 😀

    https://ww.wp.xz.cn/plugins/cmb2/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘radio primary checked value 0’ is closed to new replies.