我陷入困境让我头疼得厉害,正如你看到图片一样,这是我在事件中添加选项时的结果。
我更新了代码:wp-content/theme/mytheme/lib/metabox/function.php
$meta_boxes[] = array(
'id' => 'event_date_option',
'title' => __( 'Event options', 'mytheme' ),
'pages' => array( Custom_Posts_Type_Event::POST_TYPE ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'fields' => array(
array(
'name' => __( 'Event type:', 'mytheme' ),
'desc' => __( 'Choose event type', 'mytheme' ),
'id' => SHORTNAME . Widget_Event::EVENT_INTERVAL_META_KEY,
'type' => 'select',
'options' => array(
array( 'value'=>"n" , 'name' => __( 'Normal', 'mytheme' ) ),
array( 'value'=>"c" , 'name' => __( 'Comunity', 'mytheme' ) ),
),
),
它在事件发布中显示,但我不知道如何在添加新事件时保存或当我更新事件发布时。请帮帮我,谢谢!
答案 0 :(得分:0)
在发布时,您将能够通过hook save_post保存元数据,在您的functions.php文件中添加conde,然后创建所有元字段的数组
function wpt_save_meta($post) {
$meta = array(); //array of your meta post i.e $_POST['author_name']
// Add values of $chart_meta as custom field
foreach ($meta as $key => $value) { // Cycle through the $chart_meta array!
$value = implode(',', (array) $value); // If $value is an array, make it a CSV (unlikely)
if (get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
$id = update_post_meta($post->ID, $key, $value);
} else { // If the custom field doesn't have a value
$id = add_post_meta($post->ID, $key, $value);
}
if (!$value)
delete_post_meta($post->ID, $key); // Delete if blank
}
}
add_action('save_post', 'wpt_save_meta'); // save the custom fields
答案 1 :(得分:0)