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 :)

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?


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: