Wordpress Hook Pre Post Update

安稳与你 提交于 2019-12-06 03:55:40

问题


I am writing a wordpress plugin. I would like to to set the post status to publish if post status is future.

I know one hook that is to be used that is pre_post_update.

However where is the array of post related details stored so that I can change the post_status?

Thanks for the help


回答1:


The function that calls the pre_post_update hook appears on line 1525 of wp-includes/posts.php for me:

do_action( 'pre_post_update', $post_ID );

As you can see, it passes the ID of the post being updated when it is executed. To get the post from there, you would just call get_post(), e.g.:

function do_something_with_a_post($post_id, $post_data) {
     // now do something with $post_data
}
add_action('pre_post_update', 'do_something_with_a_post', 10, 2);

The $post variable above should reference an object with all of the various attributes about a post you are looking for, hopefully.



来源:https://stackoverflow.com/questions/2260210/wordpress-hook-pre-post-update

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!