سؤال

I have several functions that are called from inside a save_post function. However, all of the functions that use the $post object are returning incorrect values because it appears that the default value being passed to save_post is the post ID rather than the post object.

How can I pass the post object to the save_post function in addition to the post ID?

add_action('save_post', 'my_save_function');
هل كانت مفيدة؟

المحلول

Do:

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

And the $post object will be passed as second argument to your function:

function my_save_function($post_ID, $post) {

نصائح أخرى

Use get_post($post_id)

Reference:

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى wordpress.stackexchange
scroll top