Dynamically set maximum allowed rows on a repeater field on form render

Created by Phil Kurth, Modified on Wed, 23 Nov, 2022 at 11:47 AM by Phil Kurth

If you need to dynamically control the max number of rows a user can add to a repeater, you may use the af/field/before_render filter to modify the field's settings before it is rendered as per the below example.


Note: this example uses the `/name=FIELD_NAME` variant of the filter so be sure to replace FIELD_NAME with the name of the ACF field being targeted.


add_filter( 'af/field/before_render/name=FIELD_NAME', function ( $field, $form, $args ) {
  // Set the condition here to determine whether to limit the repeater rows.
  $condition = true;

  // If condition is true, limit the repeater rows to desired number. 
  if ( $condition ) {
    $field['max'] = 2;
  }

  return $field;
}, 10, 3 );

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article