I am running a function to do some stuff when save_post
triggers to use new data. However, the $post
object it returns, contains old data of the post, not new data! How can I get new post data inside my function? I have tried $WP_Query
. But still, same old data!
This is how I am doing this:
function my_awesome_func ($post_id, $post, $update) {
//my stuff
}
add_action( 'save_post_my-custom-post-type', 'my_awesome_func', 10, 3 );
Any thoughts?
I am running a function to do some stuff when save_post
triggers to use new data. However, the $post
object it returns, contains old data of the post, not new data! How can I get new post data inside my function? I have tried $WP_Query
. But still, same old data!
This is how I am doing this:
function my_awesome_func ($post_id, $post, $update) {
//my stuff
}
add_action( 'save_post_my-custom-post-type', 'my_awesome_func', 10, 3 );
Any thoughts?
Share Improve this question asked Jan 26, 2016 at 19:15 тнє Sufiтнє Sufi 1,7104 gold badges19 silver badges28 bronze badges 4 |1 Answer
Reset to default 1I'm going to post this as an answer, because it worked for me:
function my_awesome_func ($post_id, $post, $update) {
//update the value we need early
update_post_meta($post_id, 'my_meta_key', $_REQUEST['my_meta_key']);
$newValue = get_post_meta($post_id, 'my_meta_key');
}
add_action( 'save_post_my-custom-post-type', 'my_awesome_func', 10, 3 );
You could also simply use the value of $_REQUEST['my_meta_key'] directly if that works, but for my sake I wanted to update the post immediately so I could get the value via another function, not use the value immediately.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745184510a4615573.html
$_REQUEST['my-meta-key']
? – тнє Sufi Commented Jan 27, 2016 at 9:45