• Resolved wpfighter

    (@wpfighter)


    $cmb->add_field( array(
    	'name'             => 'Select Video or Image',
    	'desc'             => 'Select an option',
    	'id'               => $prefix . 'image_or_video',
    	'type'             => 'select',
    	'show_option_none' => true,
    	'default'          => 'custom',
    	'options'          => array(
    		'standard' => __( 'Option One', 'cmb2' ),
    		'custom'   => __( 'Option Two', 'cmb2' ),
    		'none'     => __( 'Option Three', 'cmb2' ),
    	),
    ) );

    I have written the above meta in my functions.php file.

    My requirement →

    when option two is chosen then I should execute some code.

    Like This this →

    If (Option 2 True) {
    <?php
                                   //some Php code
                                 ?>
    } else {
    
    <?php
                                   //some other Php code
                                 ?>
    
    }
    • This topic was modified 7 years, 4 months ago by wpfighter.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter wpfighter

    (@wpfighter)

    for example you have given how to use oembed meta in theme like this →

    Text added in a oembed field will not automatically display the embed in your theme. To generate the embed in your theme, this is a method you could use:

    $url = esc_url( get_post_meta( get_the_ID(), 'wiki_test_embed', 1 ) );
    echo wp_oembed_get( $url );
    Plugin Author Justin Sternberg

    (@jtsternberg)

    To test against a particular option, you would check if the result of get_post_meta matches one of the option keys:

    // If (Option 2 True)
    if ( 'custom' === get_post_meta( get_the_ID(), $prefix . 'image_or_video', true ) ) ) {
    	// some Php code
    } else {
    	// some other Php code
    }
    
    Plugin Author Justin Sternberg

    (@jtsternberg)

    I’ve added this example to the wiki: https://github.com/CMB2/CMB2/wiki/Field-Types#notes

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to pickup the Option’ is closed to new replies.