在wordpress中为元字段选择框

时间:2013-10-19 05:39:49

标签: php wordpress

我正在我的wp-admin中注册一个帖子,但我不想要编辑器等,所以添加一些字段。通过R& D我创建了如何添加文本框,它很棒,但现在我必须添加一个选择框,选项值应该是帖子标题。我不想通过插件来做这件事。 我将文字字段添加为:

$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'即可添加选择框,但我如何在选项中获得帖子标题值。

1 个答案:

答案 0 :(得分: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'
                    )    
        )  
    );