$cmb->add_field( array(
'name' => 'Select Video or Image',
'desc' => 'Select an option',
'id' => 'the_wiki_id_one',
'type' => 'select',
'show_option_none' => true,
'default' => 'custom',
'options' => array(
'standard' => __( 'Option One', 'cmb2' ),
'custom' => __( 'Option Two', 'cmb2' ),
'none' => __( 'Option Three', 'cmb2' ),
),
) );
以上是代码。现在假设如果我选择了Option 2,并且我想执行一个像这样的逻辑→
If (Option 2 selected) {
<?php Then execute some PHP code ?>
}
选择选项2→外行语言。我们怎样才能编程呢?
的代码答案 0 :(得分:1)
如果我做对了,那么你只需要从post meta获得该值,并制作条件。
$the_wiki_id_one = get_post_meta($post_id, 'the_wiki_id_one', true);
// Option 2 is selected
if( 'custom' === $the_wiki_id_one ){
//Then execute some PHP code
}