PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

gform_post_data filter not firing

  1. Nirav
    Member

    I am trying to change the post type of the form data but it seems like gform_post_data is not firing at all. The file is included while execution i.e. a die() in the file halts everything but inside the function nothing is executed, so I think gform_post_data filter is not even firing on my setup.

    add_filter( "gform_post_data", "ft_gf_change_post_type", 10, 2 );
    
    function ft_gf_change_post_type( $post_data, $form ) {
    	$post_data["post_type"] = "job";
    	return $post_data;
    }

    Also on Gist: https://gist.github.com/1363676

    P.S. I have gone through the forums a lot, the same filter is working for everyone but not me. Any suggestions what could be failing here?

    Posted 12 years ago on Monday November 14, 2011 | Permalink
  2. Nirav
    Member

    I have solved the problem, the form needs to have atleast one of the post related field on the form (you can add a hideme class to hide using jQuery it if you don't need it), then only it triggers the code to save it in custom post type.

    I have this code working now:

    add_filter( "gform_post_data", "ft_gf_change_post_type", 10, 2 );
    
    function ft_gf_change_post_type( $post_data, $form ) {
    	$does_form_saves_as_post = false;
    
    	foreach ( $form["fields"] as $field ) {
    		if ( in_array( $field["type"], array( "post_category", "post_title", "post_content", "post_excerpt", "post_tags", "post_custom_fields", "post_image" ) ) )
    			$does_form_saves_as_post = true;
    	}
    
    	if ( $does_form_saves_as_post )
    		$post_data['post_type'] = 'job';
    
    	return $post_data;
    }
    Posted 12 years ago on Monday November 14, 2011 | Permalink
  3. Thank you for the update and for sharing your solution.

    Posted 12 years ago on Monday November 14, 2011 | Permalink