在苏尼尔的回答的帮助下,我确切地知道了我需要做什么。
我去下载了免费版本的Metaboxhttps://wordpress.org/plugins/meta-box/
一旦我下载了它,我就把它放在child-theme/external/meta-box
并引用自child-theme/inc/events-custom-post-type.php
.
events-custom-post-type.php
看起来像这样。
require_once(get_stylesheet_directory() . \'/external/meta-box/meta-box.php\');
function custom_events ()
{
$labels = array(
\'name\' => \'Events\',
\'singular_name\' => \'Event\',
\'add_new\' => \'Add Event\',
\'all_items\' => \'All Events\',
\'add_new_item\' => \'Add Event\',
\'edit_item\' => \'Edit Event\',
\'new_item\' => \'New Event\',
\'view_item\' => \'View Event\',
\'search_item_label\' => \'Search Events\',
\'not_found\' => \'No Events Found\',
\'not_found_in_trash\' => \'No Events Found in Trash\',
\'parent_item_colon\' => \'Parent Event\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'has_archive\' => true,
\'publicly_queryable\' => false,
\'query_var\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => true,
\'supports\' => array(
\'title\',
\'editor\',
),
\'menu_icon\' => \'dashicons-calendar-alt\',
\'menu_position\' => 5,
\'exclude_from_search\' => true
);
register_post_type( \'custom_events_post_type\', $args );
}
function prefix_register_meta_boxes_events( $meta_boxes ) {
$prefix = \'custom_event_\';
$meta_boxes[] = array(
\'id\' => $prefix . \'details\',
\'title\' => \'Event details\',
\'post_types\' => \'custom_events_post_type\',
\'context\' => \'normal\',
\'priority\' => \'high\',
\'fields\' => array(
array(
\'name\' => \'Event date\',
\'desc\' => \'Select event date\',
\'id\' => $prefix . \'date\',
\'type\' => \'date\',
),
array (
\'name\' => \'Event location\',
\'desc\' => \'Location of the event\',
\'id\' => $prefix . \'location\',
\'type\' => \'text\'
)
)
);
return $meta_boxes;
}
add_action( \'init\', \'custom_events\' );
add_filter( \'rwmb_meta_boxes\', \'prefix_register_meta_boxes_events\' );
The
custom_events
函数设置自定义帖子类型,而
prefix_register_meta_boxes_events
函数设置自定义字段日期选择器。
你只需要确保prefix_register_meta_boxes_events
函数,其中显示post_types
添加您自己的自定义帖子类型注册为的内容。
之后,我在中引用了此文件child-theme/functions.php
就像这样。
require get_stylesheet_directory() . \'/inc/events-custom-post-type.php\';