2014-04-11 3 views
1

내가 게시 된 날짜를 메타 박스 필드 날짜에서 업데이트 할 때 작동하지 않습니다. save_post 후크를 사용하고 있지만 제대로 작동하지 않습니다. 게시 날짜를 업데이트하는 데 사용되는 함수는 다음과 같습니다. Wordpress 업데이트 게시 날짜

내 코드 :

// Update publisged date from date of launch for concept 

function update_concept_post_date($post_id){ 

    if (! wp_is_post_revision($post_id)){  

     $post_data = get_post($post_id); 
     $date = get_post_meta($post_id, '_cmb_concept_signup_date', true); 
     $updated_date = explode('-', $date); 
     $new_date = date("Y-m-d h:i:s", mktime(0,0,0,$updated_date[1],$updated_date[2],$updated_date[0])); 
     if($post_data->post_type == 'concepts'){ 
      $my_post = array(
       'ID'   => $post_id, 
       'post_date' => $new_date 
     ); 
      // update the post, which calls save_post again 
      wp_update_post($my_post); 
     } 
    } 
} 
add_action('save_post', 'update_concept_post_date', 10); 
+0

이것은 사용자 정의 메타입니다.이 값의 형식은 무엇입니까? –

+0

게시일의 날짜는 (Y-m-d h : i : s)입니다. –

+0

날짜 분석 섹션이 잘못되었습니다. 내 대답을 참조하십시오 –

답변

1

당신은 잘못된 날짜를 파싱, 그것은해야한다;

$temp = explode(' ', $date); 
$updated_date = explode('-', $temp[0]); 

첫째는 공백 문자에 의해 파싱하고, 첫 번째 부분은 Y-m-d하게하고 -하여이 부분을 파싱.

+0

고마워,하지만 나를 위해 작동하지 않습니다. –

+0

'if ($ post_data-> post_type == 'concepts')'조건에서'var_dump ($ my_post)'의 결과는 무엇입니까? 당신이 그걸 제공하면, 내가 도울 수 있습니다 –

+0

전체이 게시물의 데이터를 Realted. –