2017-08-01 94 views
1
$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。我們如何在編程時做到這一點?

以上是從CMB2 Wordpress Plugin

+0

該條件應放置在哪裏,某處接近$ cmb-> add_field? – PayteR

+0

沒有其他地方的主題。 – somethingnow

+0

您必須爲onChange事件創建一些JavaScript並使用Ajax請求調用PHP腳本。 –

回答

1

代碼,如果我得到它的權利,那麼你只需要從元后該值,並使條件。

$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 
}