Currently, the post status of a post generated from a Gravity Form submission is set via the Post Title, Post Body or Post Excerpt fields. So what do you do if you want the post status to be based on some form of user input? It’s a form-specific option (as opposed to field specific) which means Gravity Forms’ powerful conditional logic can not help us here.
Fortunately, the solution is quite simple. Put on your pointy wizard hats and check out this snippet.
/** | |
* Set Post Status by Field Value | |
* http://gravitywiz.com/2012/05/04/set-post-status-by-field-value/ | |
*/ | |
// update "3" to the ID of your form | |
add_filter('gform_post_data_3', 'gform_dynamic_post_status', 10, 3); | |
function gform_dynamic_post_status($post_data, $form, $entry) { | |
// update "5" to the ID of your custom post status field | |
if($entry[5]) | |
$post_data['post_status'] = $entry[5]; | |
return $post_data; | |
} |
How do I install this snippet?
Use a simple copy and paste spell to copy the snippet above and paste it in your theme’s functions.php file.
Do I need to modify the snippet to work for my form?
Yes. There are comments inline in the code which indicate where you’ll need to make modifications.
- Update the
3
in the filter namegform_post_data_3
to the ID of your own form. - Update the
5
in both places you see$entry[5]
to your field ID.
This snippet assumes the value of the specified field will be a valid post status. Here is an example of how this can be configured using a drop down field:

Is Gravity Forms made of magic? Yes and yes! The snippet to accomplish this is only slightly more involved. I’ve added this as a separate post here: Set Post Status by Field Value (Advanced)
Summary
This is the simplest method to accomplish this functionality. Make sure you check out the advanced version too!
Did this resource help you do something awesome with Gravity Forms? Then you'll absolutely love Gravity Perks; a suite of 39+ essential add-ons for Gravity Forms with support you can count on.
Thanks for the post, David.
Would it be possible to create three separate Gravity forms with the same function?
I wrote the same snippet three times on function.php, and replaced the form ID (gform_post_data_n) and field ID ($entry[n]) in each to correspond to the respective Gravity form. A refresh on the website returns a blank white page.
Hi Josh, that should work. I’m guessing there may have been a syntax error. This might help: https://gravitywiz.com/documentation/apply-class-based-snippet-different-forms/
Hi David,
I’m having the same problem as Josh. Trying to set a post status by two different forms results in a blank page. Could you please explain how the quoted article (https://gravitywiz.com/documentation/apply-class-based-snippet-different-forms/) works in connection with the snippet above?
Thanks in advance!
Hi Eckart, this is a bit simpler than a class-based snippet. You just need to have unique function names. Here’s an example: http://pastie.org/private/ppfgtq1f026dcg9ccgkag#3-4,13-14