Set Limit by Custom Field

Read the Walkthrough

Code

Filename: gpls-set-limit-by-custom-field.php

<?php
/**
 * Gravity Perks // Limit Submissions // Set Limit by Custom Field
 * https://gravitywiz.com/gravity-forms-limit-submissions/
 */
// Update "123" to your form ID.
add_filter( 'gpls_rule_groups_123', function ( $rule_groups ) {

	// Update "Your Feed Name" to the name of your Limit Submissions feed.
	$feed_name = 'My Feed Name';

	// Update "my_custom_limit" to your custom field key.
	$custom_field = 'my_custom_limit';

	$post_id = get_queried_object_id();
	if ( ! $post_id ) {
		return $rule_groups;
	}

	foreach ( $rule_groups as &$rule_group ) {
		if ( $rule_group->name == $feed_name ) {
			$rule_group->limit = get_post_meta( $post_id, $custom_field, true );
		}
	}

	return $rule_groups;
} );

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.