2013-12-08 2 views
1

프로그래밍 방식으로 사용자 정의 게시 유형을 만들고 Wordpress에 인터페이스로 업데이트하려고합니다. 다음 코드를 가지고 모든 게시/예약 상태를 제외하고 작동합니다Wordpress wp_update_post가 상태를 올바르게 업데이트하지 않습니다.

wp_update_post(
    array(
     'ID' => $id, 
     'post_title' => $page_title, 
     'post_excerpt' => $page_excerpt, 
     'post_content' => $page_content, 
     'edit_date' => true, 
     'post_date' => $publish_date, 
     'post_status' => (strtotime($publish_date) > time() ? 'future' : 'publish') 
    ) 
); 
wp_insert_post에 게시물을 작성하는 경우,이 (위와 같은 논리를 사용하여) 올바르게 상태를 설정하는 것

하지만, 날짜를 업데이트하고 그에 따라 상태를 설정하면 상태가 변경되지 않습니다.

앞으로 6 개월 후에 게시물이 생성되면 스케줄이 설정됩니다. 포스트가 과거에 post_date로 업데이트되면 날짜는 업데이트되지만 상태는 여전히 스케줄로 설정됩니다.

edit_date를 true로 설정해야 작동한다는 것을 읽었지만, 위와 같이 시도해 보았습니다.

내가 누락 된 자료가 있습니까?

미리 도움을 청하십시오.

감사합니다,

PhilHalf

답변

2

당신은 그것을 시도를 제공 할 수 있습니다

$status = strtotime($publish_date) > strtotime('today') ? 'future' : 'publish'; 
wp_update_post(
    array(
     'ID' => $id, 
     'post_title' => $page_title, 
     'post_excerpt' => $page_excerpt, 
     'post_content' => $page_content, 
     'edit_date' => true, 
     'post_date' => $publish_date, 
     'post_status' => $status, 
     'post_date_gmt' => gmdate('Y-m-d H:i:s', strtotime($publish_date)) 
    ) 
); 

this answer를 살펴 보자 (post_date_gmt 추가).

+0

트릭을 한 것 같습니다! 고맙습니다. – PhilHalf

+0

환영합니다 @PhilHalf. 다행히 도움 :-) –

관련 문제