2010-04-04 5 views
0

실제로 아래의 코드에서 각 경우에 $ postID를 반환해야합니까?이 코드에 문제가 있습니까?

이 코드는 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-includes/plugin.php에 아무것도 반환하지 않습니다 호출됩니다. 아니요, $postID을 반환 할 필요가 없습니다.

0

을 최대한 멀리 볼 수, 당신은 영감을 받고있는 코드는 $postID를 반환하지 않습니다 - 그리고 나는 그것이 필요한 것에 대해 국제 식품에서 아무것도 볼 수 없습니다. 그래서 아니야?

관련 문제