I'm try to check input data before it is added to DB. For example:
I have a custom post meta named book_isbn
in post page. I want to make sure that this variable $_POST['book_isbn']
is valid before it is added to DB.
So far I know that I can use hook wp_insert_post_data
to achieve this. I'm not sure if I did this right. It doesn't work for me. Please check the code below.
add_filter( 'wp_insert_post_data', 'clean_data_before_post_created', '99', 2 );
function clean_data_before_ad_created( $data , $postarr ) {
$data['book_isbn'] = clean_isbn($_POST['book_isbn']);
return $data;
}
Thank you.