对于我的自定义帖子类型,我需要添加属性元框,但我想添加一个额外的字段。
因此,我在这里复制了页面属性元框代码并添加了选择选项,但我需要帮助重写“模块类型”选择框,以便在保存页面时正常工作。
function page_attributes_meta_box2($post) {
$post_type_object = get_post_type_object($post->post_type);
if ( $post_type_object->hierarchical ) {
$pages = wp_dropdown_pages(array(\'post_type\' => $post->post_type, \'exclude_tree\' => $post->ID, \'selected\' => $post->post_parent, \'name\' => \'parent_id\', \'show_option_none\' => __(\'(no parent)\'), \'sort_column\'=> \'menu_order, post_title\', \'echo\' => 0));
if ( ! empty($pages) ) {
?>
<p><strong><?php _e(\'Parent\') ?></strong></p>
<label class="screen-reader-text" for="parent_id"><?php _e(\'Parent\') ?></label>
<?php echo $pages; ?>
<?php
} // end empty pages check
} // end hierarchical check.
?>
<p><strong><?php _e(\'Order\') ?></strong></p>
<p><label class="screen-reader-text" for="menu_order"><?php _e(\'Order\') ?></label><input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo esc_attr($post->menu_order) ?>" /></p>
<p><?php if ( \'page\' == $post->post_type ) _e( \'Need help? Use the Help tab in the upper right of your screen.\' ); ?></p>
<p><strong><?php _e(\'Module Type\') ?></strong></p>
<label class="screen-reader-text" for="_cnote_module_page_type"><?php _e(\'Module Type\') ?></label>
<select id="_cnote_module_page_type" name="_cnote_module_page_type">
<option value="default">Default</option>
<option value="parent">Parent</option>
<option value="chat">Chat</option>
</select>
<?php
}
add_action(\'add_meta_boxes\',\'add_post_template_metaboxr\');
function add_post_template_metaboxr() {
add_meta_box(\'postparentdiv\', __(\'Post Template\'), \'page_attributes_meta_box2\', \'module\', \'side\', \'high\');
}
**注意,我还没有重命名所有内容,这里有很多复制和粘贴