我的自定义帖子类型中有一个元框,我从前端表单接收数据。问题是,在这个函数中的某个地方,出现了一些错误,并且在管理编辑面板中更改的数据不适用于该帖子(update\\u post\\u meta没有完成他的工作,我猜),下面是我的代码:
// HANDLER FOR THE FORM AND SAVING THE RIGHT DATA
<?php elseif(isset($_POST[\'test\'])){ 
     $location = $_POST[\'_location\'];
     $new_post = array(
        \'post_title\'    =>   $_POST[\'title\'],
        \'post_content\'  =>   $_POST[\'description\'],
        \'post_status\'   =>   \'pending\',          
        \'post_type\' =>   \'eventstest\'       
        );
        $pid = wp_insert_post($new_post);
        add_post_meta($pid, \'location\', $location, true);
}
do_action(\'save_post\', \'eg_save_events_meta\', 1, 2); // save the custom fields
do_action(\'wp_insert_post\', \'wp_insert_post\'); 
// ADD THE META BOX
function add_events_metaboxes() { 
   add_meta_box(\'wpt_events_location\', \'Event Location\', \'wpt_events_location\', \'eventstest\', \'side\', \'default\');}
//DISPLAING META BOXES
function wpt_events_location() { 
global $post;
echo \'<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="\' . 
wp_create_nonce( plugin_basename(__FILE__) ) . \'" />\';
$_location = get_post_meta($post->ID, \'location\', true);
echo \'<input type="text" name="_location" value="\' . $_location  . \'" />\';}
//SAVING AND UPDATE META FIELDS
function eg_save_events_location( $post_id ){
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE ) 
    return;
if ( !wp_verify_nonce( $_POST[\'myplugin_noncename\'], plugin_basename( __FILE__ ) ) )
    return;
if ( \'page\' == $_POST[\'post_type\'] ) 
{
    if ( !current_user_can( \'edit_page\', $post_id ) )
    return;
}
else
{
    if ( !current_user_can( \'edit_post\', $post_id ) )
    return;
}
$mydata = $_POST[\'_location\'];
update_post_meta($post->ID, \'location\', $mydata);}
add_action(\'save_post\', \'eg_save_events_location\', 1, 2); // save the custom fields once again in functions.php too