How to show only the required number of repeater fields contents in a ACF plugin(WordPress)

Making use of Advanced Custom fields in WordPress is very familiar for us. This helps the user to add contents dynamically through the back end of a WordPress website with out the help of any coding experiences.

The ACF Repeater field is one of many ACF field types and is known as a complex field, mainly due to the fact it allows you to add sub fields that can be repeated over and over again when editing content.

Suppose we need to display only the first few contents of a repeater fields ,how is it possible ?

We need to loop through the sub contents of a repeater by setting a value that shows how much contents to be displayed.

    <?php
	$repeaterContents = 10; //Number of contents to display
$field = get_field('repeater name'); // replace 'my_custom_repeater' with the name of your custom field repeater
if ($field) {
    $count = 0;
    while ($count < $repeaterContents && have_rows('repeater name')) { // replace 'my_custom_repeater' with the name of your custom field repeater
        the_row();
		?>

//contents to be displayed

<?php
		$count++;
    }
}
?>


This will gives the required number of fields to be displayed on the screen.
Hope this article will be helpful .
Thank you.

Leave a comment

Your email address will not be published. Required fields are marked *