Docs & Support

Learn about all the Formidable features and get support from our amazing customer success team.

frm_new_post

This hook is used to modify the post before it is created.

Usage

add_filter('frm_new_post', 'modify_my_post', 10, 2);
function modify_my_post($post, $args)

Formidable Forms makes advanced site building simple. Launch forms, directories, dashboards, and custom WordPress apps faster than ever before.

Parameters

  • $post (array)
  • $args['form'] (object)
  • $args['entry'] (object)
  • $args['action'] (object)

Examples

Change the post parent

If you would like your created posts to have a parent, you can set it with this code.

add_filter( 'frm_new_post', 'change_my_post_parent', 10, 2 );
function change_my_post_parent( $post, $args ) {
        if ( $args['form']->id == 25 ) { //change 25 to the ID of your form
                $post['post_parent'] = 30; //change 30 to the ID of your WP parent page
	}
	return $post;
}

Use two fields for the title

When you customize the post title, it's best to not select a field to set it. This function will set the title instead of using the settings.

Note: The fields you combine will not be automatically updated if your post field is changed from the WordPress posts page.

add_filter( 'frm_new_post', 'change_my_post_title', 10, 2 );
function change_my_post_title( $post, $args ) {
    if ( $args['form']->id == 25 ) { //change 25 to the ID of your form
        $title = $_POST['item_meta'][20] .' '. $_POST['item_meta'][21] .' '. $_POST['item_meta'][22] .' '. $_POST['item_meta'][23];
        //change each number (20, 21, 22, 23) to the ID of the field to insert
        $post['post_title'] = $title;
    }
    return $post;
}

Create products in EDD

Use your forms to create downloads in Easy Digital Downloads.

add_filter('frm_new_post', 'edd_setup_files', 10, 2);
function edd_setup_files($post, $args) {
        if ( $args['form']->id != 5 ) { //change 5 to the ID of your form
		return $post;
	}

	global $frm_vars;
	// don't continue if no files were uploaded
	if( ! isset( $frm_vars['media_id'] ) || empty( $frm_vars['media_id'] ) ) {
		return $post;
	}

	$edd_files = array();
	foreach ( (array) $frm_vars['media_id'] as $media_id ) {
		foreach ( (array) $media_id as $id ) {
			$attachment = get_post( $media_id );
			$edd_files[] = array(
				'file'      => wp_get_attachment_url( $id ),
				'condition' => '',

				// change this line to get the name you want
				'name'      => basename( $attachment->guid ),
			);
		}
	}

	$post['post_custom']['edd_download_files'] = $edd_files;
	return $post;
}

Save custom date format in custom field

You may have the need to create a custom field with the data format saved differently than Formidable saves by default. This is a common with saving date fields in a different format and saving the image url for a file upload field instead of the id. When using this custom code the custom field name should not be included in your post settings for this form.

add_filter( 'frm_new_post', 'create_a_custom_field', 10, 2 );
function create_a_custom_field( $post, $args ) {
  $field_id = 25; // change 25 to the id of the field to draw from
  if ( isset( $_POST['item_meta'][ $field_id ] ) ) {
    $field_value = sanitize_text_field( $_POST['item_meta'][ $field_id ] );
    //$post['post_custom']['custom_field_name_here'] = date( 'm-d-Y', $field_value ); // uncomment to save a different date format and change 'custom_field_name_here'
  }
  return $post;
}

Store uploaded file URL in custom field

Use the following code to store an uploaded file URL in a custom field. When using this custom code the custom field name should not be included in your post settings for this form.

add_filter( 'frm_new_post', 'create_a_custom_field', 10, 2 );
function create_a_custom_field( $post, $args ) {
  $field_id = 25; // change 25 to the id of the file upload field
  if ( isset( $_POST['item_meta'][ $field_id ] ) ) {
    $field_value = sanitize_text_field( $_POST['item_meta'][ $field_id ] );
    $post['post_custom']['custom_field_name_here'] = wp_get_attachment_url( $field_value ); // change 'custom_field_name_here' to your custom field name
  }
  return $post;
}

Save entry ID in custom field

Use the following code to insert the ID of a newly created entry in a custom field. The post must be created by a Formidable form. Replace 25 with the ID of your form. Replace my_custom_field with your custom field name.

add_filter( 'frm_new_post', 'frm_save_entry_id_to_custom_field', 10, 2 );
function frm_save_entry_id_to_custom_field( $post, $args ) {
        if ( $args['form']->id == 25 ) { //change 25 to the ID of your form
		$post['post_custom']['my_custom_field'] = $args['entry']->id;
	}
	return $post;
}

Change Log

Added in version 2.0

Was this article helpful? *

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

In this article

    We have a small, but amazing team of dedicated people who are committed to helping you achieve your goals and project requirements.


    Copyright © 2025 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.

    Complete your purchase
    Special offer unlocked.
    Get 55% OFF!
    Complete Purchase
    Join 400,000+ using Formidable Forms to create form-focused solutions fast. Get Formidable Forms