Home › Forums › Backend Issues (wp-admin) › acf/save_post Generating Duplicates › Reply To: acf/save_post Generating Duplicates
OK… I’ve commented out the two ‘elseif‘ elements (as they are not currently setup for dealing with variables pre $_POST[‘acf’]). But what I’ve done is move the wp_update_post( $my_post ) to within the if statement. Can anyone confirm this is expected behaviour?
Also, I’ve noted that the post_id’s when I’m adding new ‘testimonials’ are going up in 3’s. I.e. 84, 87, 90. Is this also expected behaviour, or indicative of an issue?
// ACF Auto Titles
function my_post_title_updater( $post_id ) {
if ( get_post_type( $post_id ) == 'testimonial' ) {
$name_field = $_POST['acf'][field_556ea5ac8c15b]; // Name
$testimonial_field = $_POST['acf'][field_556ea5c68c15c]; // Testimonial
$my_post = array(
'ID' => $post_id,
'post_title' => $name_field . ' - \'' . $testimonial_field . '\'',
'post_name' => $post_id
);
wp_update_post( $my_post );
/* } elseif ( get_post_type( $post_id ) == 'client' ) {
$my_post = array();
$my_post['ID'] = $post_id;
$my_post['post_title'] = get_field( 'name', $post_id );
$my_post['post_name'] = $my_post['post_title'];
wp_update_post( $my_post );
} elseif ( get_post_type( $post_id ) == 'project' ) {
$my_post = array();
$my_post['ID'] = $post_id;
$my_post['post_title'] = get_field( 'name', $post_id );
$my_post['post_name'] = $my_post['post_title'];
wp_update_post( $my_post );
*/ }
}
add_action('acf/save_post', 'my_post_title_updater', 1);
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.