Repeater Control Type
Repeater control type let you create repeatable groups of attributes. This is perfect for blocks that need multiple instances of the same content structure, like testimonials, team members, or FAQ sections.
What is Repeater Control Type?
Section titled “What is Repeater Control Type?”A repeater control type contains multiple instances of the same set of attributes. Each instance (item) can have its own values.
Example: A testimonial block with a repeater for multiple testimonials:
- Each testimonial has: quote, author, avatar
- User can add/remove/reorder testimonials
Creating Repeater Control Type
Section titled “Creating Repeater Control Type”Step 1: Add a Repeater Attribute
Section titled “Step 1: Add a Repeater Attribute”- In block editor, click + Add Attribute
- Set Name:
testimonials - Set Type:
Repeater - Set Label:
Testimonials
Step 2: Define Sub-Fields
Section titled “Step 2: Define Sub-Fields”- In the repeater settings, add sub-fields:
- quote — Textarea
- author — Text
- avatar — Image
- Set constraints:
- Min items: 1
- Max items: 10
Step 3: Configure Template
Section titled “Step 3: Configure Template”Update your template to loop through items:
<div class="testimonials"> {% for testimonial in attributes.testimonials %} <div class="testimonial"> <blockquote>{{ testimonial.quote }}</blockquote> <div class="author"> <img src="{{ testimonial.avatar }}" alt="{{ testimonial.author }}"> <span>{{ testimonial.author }}</span> </div> </div> {% endfor %}</div>Repeater Settings
Section titled “Repeater Settings”| Setting | Description |
|---|---|
| Min items | Lowest number of items (0 for optional) |
| Max items | Highest number of items allowed |
| Collapsible | Allow users to collapse/expand items |
| Label template | Custom label for each item |
Template Example: FAQ Block
Section titled “Template Example: FAQ Block”<div class="faq-block"> {% for item in attributes.faqs %} <div class="faq-item"> <h3>{{ item.question }}</h3> <p>{{ item.answer }}</p> </div> {% endfor %}</div>Render in PHP
Section titled “Render in PHP”<?php if (!empty($attributes['testimonials'])) : ?><div class="testimonials"> <?php foreach ($attributes['testimonials'] as $item) : ?> <div class="testimonial"> <blockquote><?php echo esc_html($item['quote']); ?></blockquote> <div class="author"> <?php if (!empty($item['avatar'])) : ?> <img src="<?php echo esc_url($item['avatar']); ?>" alt=""> <?php endif; ?> <span><?php echo esc_html($item['author']); ?></span> </div> </div> <?php endforeach; ?></div><?php endif; ?>Best Practices
Section titled “Best Practices”- Set reasonable limits — Don’t allow unlimited items
- Use clear sub-field names — Makes template writing easier
- Consider performance — Too many items can slow the editor
- Group logically — Keep related fields together
Next Steps
Section titled “Next Steps”- InnerBlocks — Nest blocks within blocks
- Groups Tab — Organize attributes