Set Post Status by Field Value (Advanced)

Read the Walkthrough

Code

Filename: gw-set-post-status-by-field-value-advanced.php

<?php
/**
 * Gravity Wiz // Gravity Forms // Set Post Status by Field Value (Advanced)
 * https://gravitywiz.com/set-post-status-by-field-value-advanced/
 */
// update "123" to the ID of your form
add_filter( 'gform_post_data_123', 'gform_dynamic_post_status', 10, 3 );
function gform_dynamic_post_status( $post_data, $form, $entry ) {

	// update "4" to the ID of your custom post status field
	if ( $entry[4] ) {
		switch ( $entry[4] ) {
			case 'Yes, please review my post.':
				$post_data['post_status'] = 'pending';
				break;
			case 'No, please publish my post.':
				$post_data['post_status'] = 'publish';
				break;
		}
	}
	return $post_data;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.