Description

The wpforms_post_submissions_post_args filter is used to populate all the arguments of the submission such as title, post type, etc when using the Post Submissions addon from WPForms.

Parameters

$post_args
(array) (Required) Arguments from the post submission such as Category ID, Tag ID, Author ID, etc.
$form_data
array Form settings/data.
$fields
array Sanitized entry field values/properties.

Source

wpforms-post-submissions/class-post-submissions.php

More Information

The wpforms_post_submissions_post_args fires immediately when the submission is processed to set the post title, category, etc inside the post.

Examples

In the example code, you’ll see we’re first checking the form ID to make sure it matches the form that’s being targeted. Then we’re checking a specific field (by the fields ID) to see if it’s empty.

Just remember to change the form ID from 1378 to match your form ID and change the ’10’ to match your field ID.

If you need assistance in where to find your form and field IDs, please review this tutorial.

We’re going to see if the dropdown matches FAQ and if it does, change it from the post type of post to my_faq.

/**
 * Action that fires during form submission.
 *
 * @link   https://wpforms.com/developers/wpforms_post_submissions_post_args/
 *
 * @param  array  $post_args Sanitized entry field. values/properties.
 * @param  array  $form_data Form data and settings.
 * @param  array  $fields    Sanitized entry field values/properties.
 *
 * @return array
 */

function wpf_dev_post_submissions_post_args( $post_args, $form_data, $fields ) {

    // Only run this snippet on the form ID 1378
    if ( absint( $form_data[ 'id' ] ) !== 1378 ) {
        return $fields;
    }
	
    // If the field ID is 10 and the value of that field is equal to FAQ process the snippet
    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 );