Whenever a post on my blog gets published, I want to run the create_api_cache()
-function. To achieve this, I have the attached piece of code in my functions.php
.
It works when I publish a post directly when i’m done with writing it. But when I schedule the post for a later moment, the function doesn’t run at all. Is there another action I have to link to the function to achieve such behaviour?
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);
}
}
It seems there isn’t a way to do this kind of thing in functions.php. For now, a cronjob will be my solution.