2010-04-04 116 views
0

我是不是真的要在每種情況下返回$帖子ID,下面的代碼?這段代碼有什麼問題嗎?

這是捕捉我已經加入到WP崗位和頁面編輯自定義字段的值所需的代碼。得到了這裏的想法:http://apartmentonesix.com/2009/03/creating-user-friendly-custom-fields-by-modifying-the-post-page/

add_action('save_post', 'custom_add_save'); 

function custom_add_save($postID){ 
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { 
    return $postID; 
} 
else 
{ 
    // called after a post or page is saved 
    if($parent_id = wp_is_post_revision($postID)) 
    { 
    $postID = $parent_id; 
    } 

    if ($_POST['my_customHeader']) 
    { 
     update_custom_meta($postID, $_POST['my_customHeader'], 'my_customHeader'); 
    } 
    else 
    { 
     update_custom_meta($postID, '', 'my_customHeader'); 
    } 
    if ($_POST['my_customTitle']) 
    { 
     update_custom_meta($postID, $_POST['my_customTitle'], 'my_customTitle'); 
    } 
    else 
    { 
     update_custom_meta($postID, '', 'my_customTitle'); 
    } 
} 
     return $postID; //IS THIS EVEN NECESSARY? 
} 

function update_custom_meta($postID, $newvalue, $field_name) { 
// To create new meta 
if(!get_post_meta($postID, $field_name)){ 
add_post_meta($postID, $field_name, $newvalue); 
}else{ 
// or to update existing meta 
update_post_meta($postID, $field_name, $newvalue); 
} 
} 

回答

1

操作休想返回值。它們是由do_action('name');稱爲WP-包括/ plugin.php不返回任何東西。 所以,不,你沒有返回$postID

0

據我所看到的,你被啓發的代碼不會返回$postID - 我看不到任何東西在食品它是必要的。所以不行?