How to Use the Post Submissions Addon to Post to Other Post Types

Overview

Would you like to use the Post Submissions addon to post to something other than blog articles? If you have posts on your site such as portfolio items, digital products, recipes and more, you can use a small PHP snippet to easily have your form post to these other post types. In this tutorial, we’ll walk you through the steps needed to achieve this.

Setup

By default, the Post Submissions addon will take any submission and add it to the WordPress post type of post.

For the purpose of this tutorial, we’ve already created our custom post type that will create FAQs on our site.

1) Setting up the form

First, you’ll need to create your form. If you need assistance in this, please review this tutorial.

We’re going to create a form that will collect FAQs from all around our community. The form will only need the Name, Email Address, Post Title and Post Content for that FAQ.

The form ID we’ve created for this tutorial is 1368, the custom post type we’re using is my_faq and the field ID for our dropdown so our users can choose what type of submission they want to submit is 10.

we've now created the form to accept the post submissions. In the next step, we'll add the custom snippet to bring it all together.

2) Adding the code snippet

Next, copy this code snippet to your site and make the necessary changes for the form ID, field ID and the custom post type name.

/**
 * Change the default post type for Post Submissions addon.
 *
 * @link https://wpforms.com/developers/how-to-use-the-post-submissions-addon-to-post-to-other-post-types/
 *
 */
function wpf_dev_post_submissions_post_args( $post_args, $form_data, $fields ) {
    if ( absint( $form_data['id'] ) !== 1378 ) {
        return $fields;
    }
	
	if ( ! empty( $fields['10'] ) && $fields['10']['value'] === 'FAQ' ) {
		$post_args['post_type'] = 'my_faq';
	}
	return $post_args;
}
  
add_filter( 'wpforms_post_submissions_post_args', 'wpf_dev_post_submissions_post_args', 10, 3 );

Using this filter you can now use the Post Submissions form to post to any custom post type.

And that’s it! You’ve successfully used your form to post to custom post types. Would you like to use this addon to also create a form for profiles? Check out our tutorial on How to Build a Profile Form Using Post Submissions.

Filter Reference: wpforms_post_submissions_post_args