Support

Account

Home Forums General Issues ACF frontend form

Helping

ACF frontend form

  • Hi,

    Is it possible to create post in multiple post type with one form submission?

    Example : i have 2 custom post type “custom_post_type_a” & “custom_post_type_b”, what i wanted to archive is when user doing a submission in the front end, automatically the “custom_post_type_a” & “custom_post_type_b” will create a new post.

    Currently i able to create single post type only when user submit the form.

  • You can only create one post automatically with a front end form, which is the same way that WP works in the back end.

    If I needed to do this I would create and acf/save_post filter that runs after ACF (priority 20) https://www.advancedcustomfields.com/resources/acfsave_post/ In this filter I would get the information from the post that was saved and duplicate it into the other post type. You might want to see if it was already done and if it’s the right post type.

    Here are some basics

    
    add_action('acf/save_post', 'duplicated_acf_form_post');
    function duplicated_acf_form_post($post_id) {
      if (is_admin()) {
       // since this is for a front end form
       // return if we're in the admin
       return;
      }
      if (get_post_type($post_id) != 'your-custom-post-type') {
        // not what you want to duplicate
        return;
      }
      // get post values, or something unique
      // from this post to compare to the other post type posts
      // to see if the duplicate already exists
      // user wp_insert_post() to insert a new post
      // https://developer.wordpress.org/reference/functions/wp_insert_post/
      // or wp_update_post() to update an existing post
      // https://developer.wordpress.org/reference/functions/wp_update_post/
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘ACF frontend form’ is closed to new replies.