我想在帖子发布、更新或计划后触发一个功能。我使用了
save_post
钩子,它非常适合发布和更新帖子。但没有按照预定的帖子工作。
我尝试了一些 WordPress 挂钩,但它无法正常工作。
我认为你应该尝试“future_to_publish”操作来完成任务。它会对你有帮助。
function scheduled_post_published($object)
{
// whatever it is you need to do
}
add_action('future_to_publish', 'scheduled_post_published');
时触发该功能,因为您手动发布了它或安排了稍后的任何时间发布,那么您可以使用操作钩子transition_post_status
。
add_action( 'transition_post_status', 'my_custom_function', 10, 3 );
function my_custom_function( $new_status, $old_status, $post ) {
if ( 'publish' == $new_status ) {
// Do something...
}
}