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 );
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.