Home Forums Front-end Issues Testing for duplicates before saving post using form Reply To: Testing for duplicates before saving post using form

  • In trying to sort this out, it seems to boil down to the fact that the post is being saved no matter what. I want to circumvent the save if certain criteria are not met. In this case, that no previous post exists with the same title in a published state.

    In my code sample, I am leaving the testing for that out because the primary issue is that I can’t seem to find a way to terminate the process before the pose gets saved. I am missing some step I think.

    In my plugin file I make a call to:

    add_action( ‘acf/pre_save_post’, ‘my_custom_post_type_function’, 1 );

    function my_custom_post_type_function() {
    // For the test, just terminate and return

    My Template file to create a new post entry looks like this:

    * Template Name: Post Entry for CPT
    * @package WordPress
    * @subpackage Twenty_Twelve
    * @since Twenty Twelve 1.0
    acf_form_head(); ?>
    <?php get_header(); ?>

    <div id=”primary” class=”content-area”>
    <div id=”content” class=”site-content” role=”main”>
    <?php /* The loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>
    <?php acf_form( array(
    ‘post_id’ => ‘new_post’,
    ‘new_post’ => array(
    ‘post_type’ => ‘custom-post’,
    ‘post_status’ => ‘publish’,
    ‘category’ => ‘custom-post-category’,
    ‘submit_value’ => ‘Create a new post entry’

    )); ?>
    <?php endwhile; ?>
    <!– #content –>
    </div><!– #primary –>

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>