acf_frontend/save_post

acf_frontend/save_post

Description

This action hook fires when a post is saved.

This action allows you to hook in after the form saves data to a new or existing post, making it useful to perform additional functionality when adding or updating your posts.

This action can be used on the front end instead of the acf/save_post action hook.

Important: this hook will only be fired when saving a post. If you are saving user data, please use acf_frontend/save_user.

Parameters

do_action( 'acf_frontend/save_post', $form, $post_id );
  • $form (array) The form settings, including $form[‘record’][‘post’] which contains all of the submitted post fields’ data.
  • $post_id (int|string) The ID of the post being edited.

Examples

Send email after post is saved.

This example demonstrates how to send an email after the post has been saved. Place this in your functions.php or a dedicated code snippets plugin.

functions.php

add_action('acf_frontend/save_post', 'my_acff_save_post', 10, 2);
function my_acff_save_post( $form, $post_id ) {
    
    //get important fields
    $post_content = get_post_field('post_content',$post_id);
    $post_title = get_post_field('post_title',$post_id);
    $email_address = get_field('email_address', $post_id);
    
    if( $email_address ) {
        $email_sent = wp_mail( $email_address, $post_title, $post_content );
    }
}

acf/save_post comparison

This hook is a bit different from acf/save_post so be aware of these differences:

  • $post_id is the second of two parameters, so make sure to include both parameters and to set the fourth argument of add_action to “2”.
  • This hook is always fired after the fields have been saved so none of the fields will be in the $_POST global but rather within the $form[‘record’][‘post’] array.
  • This hook only fires when saving posts. When saving user data, please use acf_frontend/save_user.

acf_frontend/save_post

Still stuck? 
Contact our support team here.

Get the free plugin and receive updates