Home › Forums › General Issues › Using acf_form – add post title… › Reply To: Using acf_form – add post title…
You need to use ACF’s acf/save_post
action hooks for this. I have seen this code somewhere here in the forum, but can’t find the link to that, so I’m pasting it below:
function ps_acf_save_post( $post_id ) {
// Don't do this on the ACF post type
if ( get_post_type( $post_id ) == 'acf' ) return;
// Get the Fields
$fields = get_field_objects( $post_id );
// Prevent Infinite Looping...
remove_action( 'acf/save_post', 'my_acf_save_post' );
// Grab Post Data from the Form
$post = array(
'ID' => $post_id,
'post_type' => 'post',
'post_title' => $fields['new_title']['value'],
'post_content' => $fields['new_description']['value'],
'post_status' => 'publish'
);
// Update the Post
wp_update_post( $post );
// Continue save action
add_action( 'acf/save_post', 'my_save_post' );
// Set the Return URL in Case of 'new' Post
$_POST['return'] = add_query_arg( 'updated', 'true', get_permalink( $post_id ) );
}
add_action( 'acf/save_post', 'ps_acf_save_post', 10, 1 );
new_title is a my custom field to be replicated for the Title and new_description for the content.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.