我有几个从内部调用的功能 save_post 功能。但是,所有使用的功能 $post 对象返回不正确的值,因为看来默认值传递给 save_post 是帖子ID,而不是帖子对象。

我如何将邮政对象传递给 save_post 功能除了邮政ID吗?

add_action('save_post', 'my_save_function');
有帮助吗?

解决方案

做:

add_action('save_post', 'my_save_function', 10, 2);

$post object 将作为第二个参数传递给您的函数:

function my_save_function($post_ID, $post) {

其他提示

利用 get_post($post_id)

参考:

http://codex.wordpress.org/function_reference/get_post

许可以下: CC-BY-SA归因
scroll top