Advanced custom fields on save function trigger, in this tutorial I am going to share a PHP programme to automatic trigger when a advance custom field save or update from back-end. Recently I have to implement something like in a project, when a mentor create a session for students it will send whats app message to all students have the selected category. To save time I used advance custom field free version. you can see the screen shot given below …
Advance custom field on save Field group Screenshot
Advanced custom fields on save function trigger WordPress Code
// on save / update trigger
function save_updated_acf_fields($post_id)
{
//var_dump($fieldD);
add_action('save_post', 'something_process',11,11);
function something_process()
{
$session_name=get_the_title();
$catId = get_field('field_668b804f201f2', $post_id);
$email = get_field('field_65d975036d82f', $post_id);
$mentor_name = get_field('field_65d975b86d831', $post_id);
$on_date = get_field('field_65642827439ed', $post_id);
$sendMsg = get_field('field_66978ee20ee08', $post_id);
$fieldD=array(
'session_name'=> $session_name,
'cat_id'=> $catId,
'on_date'=> $on_date,
'mentor_name'=> $mentor_name,
'email'=> $email,
'sendMsg'=>$sendMsg
);
print_r($fieldD);
$tmp = fopen(dirname(__file__).'/my_logs.txt', "a+"); fwrite($tmp,"\r\n\r\n".ob_get_contents());
fclose($tmp);
}
}
add_action('acf/save_post', 'save_updated_acf_fields');
You can use the code above in wordpress functions.php , also my_logs.txt we can use for debugging purpose. You can also read our tutorial on advance custom filed Advanced custom field how to populate select field.
If you have and query or suggestion then please comment, I will reply to fix your problem, if you like our content then you can subscribe to our Youtube channel. If you want to hire me then reach us at our Fiverr.
Thanks a lot ….