Support

Account

Home Forums Front-end Issues acf_form() always creates two posts Reply To: acf_form() always creates two posts

  • Hi a quick solution for this issue is to prevent post to save if the title(or anything you want) already exists, paste this code in your function.php
    it’s also recommended to add more conditions to your if statement like post type as this function might affect other plugins

    /*Check if post is duplicated*/
    function disable_save( $maybe_empty, $postarr ) {
    	if ( ! function_exists( 'post_exists' )) {
        require_once( ABSPATH . 'wp-admin/includes/post.php' );
    	}
        if(post_exists($postarr['post_title']) && $postarr['post_type'] == '/*your post type name*/' )
        {
            /*This if statment important to allow update and trash of the post and only prevent new posts with new ids*/
            if(!get_post($postarr['ID']))
        	{
        	      $maybe_empty = true;
            }
        }
        else
        {
        	$maybe_empty = false;
        }
    
        return $maybe_empty;
    }
    add_filter( 'wp_insert_post_empty_content', 'disable_save', 999999, 2 );