我有一个自定义帖子类型事件。我也有自定义元框(例如该事件发言人的下拉列表)。但是,演讲者列表是我硬编码的,客户希望能够从管理部分添加、编辑和删除演讲者。
我该怎么做呢?
$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
)
);