2013-10-19 57 views
-2

我在我的wp-admin註冊了一篇文章,但我不想編輯器等,所以添加了一些字段。由R & D我創建瞭如何添加文本框,它很棒,但現在我必須添加一個選擇框,選項值應該是發佈標題。我不想通過插件來做到這一點。 我添加文本字段:wordpress for meta field中的選擇框

$client_meta_box = array(
    'id' => 'meta-client', 
    'title' => __('Client Options','mfn-opts'), 
    'page' => 'client', 
    'context' => 'normal', 
    'priority' => 'high', 
    'fields' => array(

     array(
      'id' => 'post-link', 
      'type' => 'text', 

      'title' => __('Link', 'opts'), 
      'sub_desc' => __('Link to client`s site', 'opts'), 
     ), 

    ), 
); 

,我可以添加選擇框,通過只是改變了類型爲'type' => 'select',但我怎麼得到選項文章標題值。

+0

1 downvote +指着我的錯,我很高興這一點。 – Dinesh

回答

1

Using this to add meta box lile text, chackbox, selectoption.

$meta_boxes[] = array(
    'id' => 'meta-client',  // meta box id, unique per meta box 
    'title' => 'Client Options', // meta box title 
    'pages' => array('client'), // post types, accept custom post types as well, 
            //default is array('post'); optional 
    'priority' => 'high', // order of meta box: high (default), low; optional 
    'fields' => array( 
     array( 
      'label'=> 'Text Input', 
      'desc' => 'A description for the field.', 
      'id' => $prefix.'text', 
      'type' => 'text' 
     ), 
     array( 
      'label'=> 'Textarea', 
      'desc' => 'A description for the field.', 
      'id' => $prefix.'textarea', 
      'type' => 'textarea' 
     ), 
     array( 
      'label'=> 'Checkbox Input', 
      'desc' => 'A description for the field.', 
      'id' => $prefix.'checkbox', 
      'type' => 'checkbox' 
     ), 
     array( 
      'label'=> 'Select Box', 
      'desc' => 'A description for the field.', 
      'id' => $prefix.'select', 
      'type' => 'select', 
      'options' => array(
         'option1' => 'Optionone', // 'value'=>'label' 
         'option2' => 'Optiontwo', 
         'option3' => 'Optionthree' 
        )  
     ) 
    ); 
+0

我添加了你的選項值,它在下拉列表中顯示三個數組,不像一個,兩個,三個數值,以及如何在選項中獲得帖子標題....謝謝 – Dinesh

+0

我已經改變了我的選擇代碼,工作正常。 –

+0

+1如何添加選擇框,現在如何獲得選項中的帖子標題值...? – Dinesh