Close Comments when Post Created via Gravity Forms

This simple snippet allows you to close comments on posts created via a Gravity Form.

Read the Walkthrough

Code

Filename: gw-close-comments-on-post-creation.php

<?php
/**
 * Gravity Wiz // Gravity Forms // Close Comments when Post Created via Gravity Forms
 * https://gravitywiz.com/close-comments-when-post-created-via-gravity-forms/
 *
 * This simple snippet allows you to close comments on posts created via a Gravity Form.
 */
// Update the "123" to the ID of your form.
add_filter( 'gform_post_data_123', function( $post_data ) {

	$post_data['comment_status'] = 'closed';

	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.