WordPress save_post hook has the wrong post?

I’m getting some odd results saving meta values to my custom post types using the save_post hook. The data is saved to the incorrect post.

If I log the post ID using the code below, i see that the is is not the correct, that is while i edit post 7890, the log entry is 3345 (and thats where the saved data is put)

Have i misunderstood how the save_post hook works? Any help appreciated 🙂

add_action('save_post','save_data');
function save_data($post_id){
        $file = 'log.txt';
        $copystring = $post_id ."n";
        file_put_contents($file, $copystring, FILE_APPEND | LOCK_EX);
    }

thank you

Read more here: WordPress save_post hook has the wrong post?

Leave a Reply

Your email address will not be published. Required fields are marked *