PHP code example of manzoorwanijk / cmb2-select-plus

1. Go to this page and download the library: Download manzoorwanijk/cmb2-select-plus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

manzoorwanijk / cmb2-select-plus example snippets


// Select Field without optgroup
$cmb->add_field( array(
	'name'		=> 'Normal Select',
	'id'		=> $prefix . 'normal_select',
	'type'		=> 'select_plus',
	'options'	=> array(
		'standard' => 'Option One',
		'custom'   => 'Option Two',
		'none'     => 'Option Three',
	),
) );

$cmb->add_field( array(
	'name'		=> 'Select+',
	'desc'		=> 'field description (optional)',
	'id'		=> $prefix . 'smart_select',
	'type'		=> 'select_plus',
	'options'	=> array(
		'Basic'	=> array( // optgroup
			1	=> 'Option One',
			2	=> 'Option Two',
			3	=> 'Option Three',
		),
		'Advanced'	=> array( // optgroup
			4	=> 'Option Four',
			5	=> 'Option Five',
			6	=> 'Option Six',
		),
	),
) );

// Select Field without optgroup and with multiple attribute
$cmb->add_field( array(
	'name'		=> 'Normal Select',
	'id'		=> $prefix . 'normal_select_multi',
	'type'		=> 'select_plus',
	'options'	=> array(
		'standard' => 'Option One',
		'custom'   => 'Option Two',
		'none'     => 'Option Three',
	),
	'attributes'	=> array(
		'multiple'	=> 'multiple',
	),
) );

// Select Field with optgroup and multiple attribute
$cmb->add_field( array(
	'name'		=> 'Select+',
	'desc'		=> 'field description (optional)',
	'id'		=> $prefix . 'smart_select_multi',
	'type'		=> 'select_plus',
	'options'	=> array(
		'Basic'	=> array( // optgroup
			1	=> 'Option One',
			2	=> 'Option Two',
			3	=> 'Option Three',
		),
		'Advanced'	=> array( // optgroup
			4	=> 'Option Four',
			5	=> 'Option Five',
			6	=> 'Option Six',
		),
	),
	'attributes'	=> array(
		'multiple'	=> 'multiple',
	),
) );

// field args
$args = array(
    'field_args'    => array(
        'id'        => 'some_id_here',
        'type'      => 'select_plus',
        'options'   => array(
            'standard' => 'Option One',
            'custom'   => 'Option Two',
            'none'     => 'Option Three',
        ),
) );
// create field
$field = new CMB2_Field( $args );

// pass the field to custom class
$types = new Select_Plus_CMB2_Types( $field );

// render the field with new id and name
echo $types->select_plus( array(
    'id'    => 'new_id_0_here',
    'name'  => 'smart[param][value]',
) );