如何select选项条件?
How to select the options condition?
$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' ),
),
) );
以上是代码。现在假设如果我选择了选项二,并且我想执行这样的逻辑 →
If (Option 2 selected) {
<?php Then execute some PHP code ?>
}
已选择选项 2 → 外行语言。我们如何在编程方面做到这一点?
的代码
如果我做对了,那么您只需要从 post 元数据中获取该值,然后设置条件即可。
$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
}
$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' ),
),
) );
以上是代码。现在假设如果我选择了选项二,并且我想执行这样的逻辑 →
If (Option 2 selected) {
<?php Then execute some PHP code ?>
}
已选择选项 2 → 外行语言。我们如何在编程方面做到这一点?
的代码如果我做对了,那么您只需要从 post 元数据中获取该值,然后设置条件即可。
$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
}