save_post returning old post meta
-
I’ve been banging my head against the wall for quite some time now to no avail. According to the comments in post.php (and online), the
save_postaction is supposed to fire after the post and post meta have been saved to the database.When I attempt to retrieve the post meta from this action, I am only getting the post meta before the save. I’ve created a clean install with no plugins and am able to replicate the results. Please find my code below.
function update_custom_field( $post_id, $post, $update ) { $myfile = fopen( 'test.txt', 'w' ); fwrite( $myfile, print_r( get_post_meta( $post_id ), true ) ); fclose( $myfile ); } add_action( 'save_post', 'update_custom_field', 20, 3 );In order to see the new post meta in the file, I have to save the post twice.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘save_post returning old post meta’ is closed to new replies.