Skip to content

Commit bfa828b

Browse files
authored
gpls-set-limit-by-custom-field.php: Created new snippet.
1 parent aa60b3a commit bfa828b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Limit Submissions // Set Limit by Custom Field
4+
* http://gravitywiz.com/gravity-forms-limit-submissions/
5+
*/
6+
// Update "123" to your form ID.
7+
add_filter( 'gpls_rule_groups_123', function ( $rule_groups ) {
8+
9+
// Update "Your Feed Name" to the name of your Limit Submissions feed.
10+
$feed_name = 'My Feed Name';
11+
12+
// Update "my_custom_limit" to your custom field key.
13+
$custom_field = 'my_custom_limit';
14+
15+
$post_id = get_queried_object_id();
16+
if ( ! $post_id ) {
17+
return $rule_groups;
18+
}
19+
20+
foreach ( $rule_groups as &$rule_group ) {
21+
if ( $rule_group->name == $feed_name ) {
22+
$rule_group->limit = get_post_meta( $post_id, $custom_field, true );
23+
}
24+
}
25+
26+
return $rule_groups;
27+
} );

0 commit comments

Comments
 (0)