2011-08-01 4 views
0

게시 된 게시물의 내용을 편집하는 플러그인을 작성하려고합니다. 나는 이것을 사용해 보았다 :게시물을 플러그인을 통해 게시 한 후 수정 하시겠습니까?

function edit($post_ID) { 
    $content = "Hello. This is a test."; 

    $post_info = get_post($post_ID);  
    $post_info->post_content = "$content"; 

    wp_update_post($post_info); 
} 

add_action('publish_post', 'edit'); 

그것은 효과가 없지만. 루프를 입력하면 (다시 게시되기 때문에) 타임 아웃 할 때만 종료됩니다. 이 작업을 수행 할 수있는 다른 방법이 있습니까?

답변

0

나는 함수가 호출되었는지 추적하는 함수에 정적 변수가 있어야한다고 생각한다. 또한 wp_update_post는 객체가 아닌 배열을 사용합니다. 적어도 그렇게하는 방법입니다.

function edit($post_ID) { 
    static $plugin_has_updated = false; 
    if ($plugin_has_updated) return; 
    $plugin_has_updated = true; 
    $content = "Hello. This is a test."; 
    $post_arr = array("ID"=>$post_ID, "post_content"=>$content); 
    wp_update_post($post_arr); 
} 

add_action('publish_post', 'edit'); 
관련 문제