Wordpress-如何将固定数据动态添加到元框中


Wordpress - How to dynamically add fixed data to meta boxes

我有一个自定义的帖子类型Event。我也有自定义的元框(例如,该事件发言人的下拉列表)。然而,演讲者列表是由我硬编码的,客户希望能够添加、编辑演讲者,并从管理部分删除这些演讲者。

我该怎么做?

$items = get_posts( array (  
    'post_type' => YOUR_POST_TYPE,  
    'posts_per_page' => -1,
    'post_status' => 'publish' 
)); 
<select name="get-posts" id="get-posts"> 
            <option value="">Choose A Page</option>
            <?php   
        foreach($items as $item) {  
            echo '<option value="'.$item->ID.'"',$meta == $item->ID ? ' selected="selected"' : '','>'.$item->post_title.'</option>';  
        } // end foreach ?> 
</select>

您可以通过自定义元盒来完成,这是代码形式codex

register_taxonomy( 
  'speakers', 
  array( 'YOUR_POST_TYPE' ), 
  array( 
    'hierarchical' => true, 
    'labels' => array(
        'name'              => _x( 'Speakers', 'taxonomy general name' ),
        'singular_name'     => _x( 'Speaker', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Speakers' ),
        'all_items'         => __( 'All Speakers' ),
        'parent_item'       => __( 'Parent Speakers' ),
        'parent_item_colon' => __( 'Parent Speakers:' ),
        'edit_item'         => __( 'Edit Speakers' ),
        'update_item'       => __( 'Update Speakers' ),
        'add_new_item'      => __( 'Add New Speakers' ),
        'new_item_name'     => __( 'New SpeakersName' ),
        'menu_name'         => __( 'Speakers' ),
    ), 
    'rewrite' => true 
  ) 
);