2011-08-14 8 views
0

파일을 저장할 때마다 save_post 후크를 사용하여 html 파일을 만들려고했습니다.WP 후크 기능 'save_post'

, WP는

메시지 반환하는 내용을 편집 한 후 기존 게시물을 업데이트하려고 노력하지만, "사과를 찾을 수 없음을, 그러나 당신이 요청하신 페이지를 찾을 수 없습니다. 아마도 검색이 도움이 될 것입니다."

포스트는 WP로 업데이트되지 않으며 'write_single_post'함수는 의도 한대로 html 파일을 생성하지 않습니다.

function write_single_post($post_ID) 
{ 
global $folder; 

$file = $folder.$post_ID.".html"; 

$fh = fopen($file, 'w') or die("can't open file"); 
$string ="data goes here\n"; 
echo (fwrite($fh,$string))?"written":"not writtern"; 
fclose($fh); 
} 

do_action('save_post','write_single_post',$post_ID); 

답변

4

do_action() 새로운 후크를 생성 ..... 방식에 문제가 아무것도 기능 거기에 후크가 사용됩니다. add_action()은 기존 후크를 사용합니다. 예를 들어,

function write_single_post($post_ID) 
{ 
global $folder; 

$file = $folder.$post_ID.".html"; 

$fh = fopen($file, 'w') or die("can't open file"); 
$string ="data goes here\n"; 
echo (fwrite($fh,$string))?"written":"not writtern"; 
fclose($fh); 
} 

add_action('save_post','write_single_post'); 

는 단지이 경우 후크 & 당신의 기능을 필요로한다. 게시물 ID는 자동으로 전달됩니다.