Add a number field in CMB2

CMB2 doesn’t have a number type instead a text field is used and adding the attribute of number which makes it a number field.

$cmb_superfield->add_field( array(
‘name’ => ‘Superfield’,
‘desc’ => __( ‘This controls the order’, ‘cmb2’ ),
‘id’ => $prefix . ‘popularity’,
‘type’ => ‘text’,
‘attributes’ => array(
‘type’ => ‘number’,
),
) );

Add your comment