2016-11-14 93 views
0

我有一个卡住,让我很头痛,因为你看到的图片,这是我的结果,当我添加选项的事件。添加选项的事件(WordPress的)

enter image description here

我更新代码: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

上发布,你将能够通过挂钩save_post保存您的元数据,添加的部份孔德在functions.php文件,只是创建的所有元场的阵列

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