【发布时间】:2014-04-26 05:55:10
【问题描述】:
每当我博客上的帖子发布时,我都想运行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);
}
}
【问题讨论】:
-
对 WordPress 不了解,但我猜在发布预定帖子时使用了不同的功能。
-
您是否希望在预定帖子的发布日期临近时触发该操作?
-
有趣。我希望这能奏效。你如何测试这个?
-
@s_ha_dum 通过实际安排一个帖子并等待它发布。