ブログの投稿が公開されるたびに、関数を実行したいと考えていcreate_api_cache()
ます。これを実現するために、添付のコードをfunctions.php
.
書き終わったときに投稿を直接公開すると機能します。しかし、投稿を後でスケジュールすると、機能がまったく実行されません。そのような動作を実現するために関数にリンクする必要がある別のアクションはありますか?
add_action('new_to_publish', 'create_api_cache');
add_action('draft_to_publish', 'create_api_cache');
add_action('pending_to_publish', 'create_api_cache');
add_action('pre_post_update', 'create_api_cache');
add_action('future_to_publish', 'create_api_cache');
function create_api_cache() {
global $post;
$postname = $post->post_name;
if(strlen($postname)) {
$url = 'http://api.dummydomain.com/1/cache/create/' . $postname;
file_get_contents($url);
}
}