Support

Account

Home Forums General Issues Issues with multiples ACF Form

Solved

Issues with multiples ACF Form

  • Hi, I want to create several multiples ACF Form to allow users to suggest content directly through the front-end.

    To do that, I created multiples functions in my functions.php. Each one have a different ‘post_type’ value and named differently.

    I have done the same in my templates, specifying differents “field_groups” value but when I test my forms, all the content are going in the post type “one”.

    I checked my two pages and they both point to different templates.

    Do you know how can I fix this problem ?

    Thanking you in advance,
    Willwoody.

    Here’s my functions.php’s code :

    /*
     * Pre save post "One"
     */
    
    function my_pre_save_post_one( $post_id ) {
     
        // check if this is to be a new post
        if( $post_id != 'new' )
        {
            return $post_id;
        }
     
        // Create a new post
        $post = array(
            'post_status'  => 'pending',
            // 'post_title'    => $_POST['acf']['field_5c4efddbb8d24'].' '.$_POST['acf']['field_5c4efdd6b8d23'].' - '.$_POST['acf']['field_5c4efdfeb8d27'],
            'post_type'  => 'cpt_one',
        );
     
        // insert the post
        $post_id = wp_insert_post( $post );
     
     
        // return the new ID
        return $post_id;
    }
     
    add_filter('acf/pre_save_post' , 'my_pre_save_post_cpt_one' );
    
    /*
     * Pre save post "Two"
     */
    
    function my_pre_save_post_satc( $post_id ) {
     
        // check if this is to be a new post
        if( $post_id != 'new' )
        {
            return $post_id;
        }
     
        // Create a new post
        $post = array(
            'post_status'  => 'pending',
            'post_title'    => $_POST['acf']['field_5c5ab409c12de'].' '.$_POST['acf']['field_5c5ab409c12ba'].' - '.$_POST['acf']['field_5c5ab409c133d'],
            'post_type'  => 'cpt_two',
            'submit_value'	=> 'Submit',
        );
     
        // insert the post
        $post_id = wp_insert_post( $post );
     
     
        // return the new ID
        return $post_id;
    }
     
    add_filter('acf/pre_save_post' , 'my_pre_save_post_cpt_two' );
  • You need to use a different value for post ID in one of your forms

    
    if( $post_id != 'new' )
        {
            return $post_id;
        }
    

    This is the same in both functions, only one of your filters will ever run.

    Use unique “post_id” values, like “new_cpt_one” and “new_cpt_two”

  • Thanks you It works!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Issues with multiples ACF Form’ is closed to new replies.