Outputting Only the First ACF Repeater Row in Bricks

Updated on 12 Dec 2023

In the Bricks Facebook group a user asks:

How can I display only the first entry from an ACF repeater?

This can be done using the bricks/query/result filter through which all query types go through. This enables us to modify the array that the loop iterates through and restrict it to just the first one, in this case.

Add the following in child theme‘s functions.php or a code snippets plugin:

add_filter( 'bricks/query/result', function( $result, $query_obj ) {
  if ( $query_obj->element_id !== 'uxigqi' ) return $result;

  // return the first result
  return array_slice( $result, 0, 1 );
}, 30, 2);

Replace uxigqi with the Bricks ID of your query loop element.

Before:

After:

Powerful filters such as these are one of the reasons that make Bricks a developer’s dream.

Thanks to Jenn Lee for reminding me the filter name.