Basically, I need to alter the info the user inputs into an advanced custom fields textbox before it is written to the database but I don’t know how to grab it. I can only get it after it has been written to the meta portion of the database by using get_field().
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Edit – This answer is no longer accurate for the current version of ACF, see their documentation
Use the acf_save_post hook.
function my_acf_save_post( $post_id )
{
// vars
$fields = false;
// load from post
if( isset($_POST['fields']) )
{
$fields = $_POST['fields'];
}
// ...
}
// run before ACF saves the $_POST['fields'] data
add_action('acf_save_post', 'my_acf_save_post', 1);
// run after ACF saves the $_POST['fields'] data
add_action('acf_save_post', 'my_acf_save_post', 20);
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0