Skip to main content Skip to navigation Skip to footer

How to Trigger a Notification from an ACF Front-end Form

Updated

If you use Advanced Custom Fields (ACF) and want to trigger a notification off of a front-end form, or edit a form after it’s been submitted but before the notification is triggered, you can do the following:

Create a custom page template that contains this code:

acf_form(array(
'post_title' => true,
'post_content' => true,
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'post',
'post_status' => 'draft'
),
'field_groups' => array(24), // Change this to the field group that you want to show
'submit_value' => 'Create a new post',
'updated_message' => 'Post updated'
));

Then add this to your functions.php file:

// Trigger BNFW 'Post Pending Review' notification on ACF front-end form save
function bnfw_after_save_post_pending($post_id) {
// Get the post object, post type, post status
$post = get_post($post_id);
$post_type = get_post_type($post_id);
$old_status = $post->post_status;
// Check if the post is the post type and status that we want
if ($post_type === 'post' && $old_status === 'draft') {
global $wpdb;
// Remove the action that triggers the notification in BNFW
$bnfw = BNFW::factory();
remove_action( 'pending_submissions', array( $bnfw, 'on_post_pending' ), 10, 2);
// Update the post title with the 'text' custom field from ACF and trigger the notification manually
wp_update_post(array(
'ID' => $post_id,
'post_title' => get_field('text', $post_id),
'post_status' => 'pending'
));
}
}
add_action('acf/save_post' , 'bnfw_after_save_post_pending', 20 );

Privacy Overview

This website uses cookies so that it can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to this website and helping employees to understand which sections of the website you find most interesting and useful.

Strictly Necessary Cookies

This website uses the Stripe Payment Processor. Cookies from Stripe are required in order for this website to provide eCommerce functions, such as to accept payments.

This website uses YouTube to host and display videos relating to the operation of this plugin and forms part of the documentation. Use of cookies from YouTube is required in order to fully document or explain elements of a product.

PHPSESSID - This cookie is native to PHP applications. The cookie is used to store and identify a users' unique session ID for the purpose of managing a user's session on the website. The cookie is a session cookies and is deleted when all the browser windows are closed.