I have setup an ACF Repeater field, but only want to show the first row.
How would I go about this?
You can limit your ACF repeater query to its first row using the bricks/query/result filter. Add this to your child theme’s functions.php or a PHP snippets plugin:
add_filter( 'bricks/query/result', function( $results, $query ) {
if ( $query->element_id === 'abcdef' && is_array( $results ) ) {
return array_slice( $results, 0, 1 );
}
return $results;
}, 10, 2 );
Replace abcdef with the ID of the element that has your ACF repeater query enabled, without the brxe- prefix. Keep your repeater subfield elements inside that loop element.
Thanks!
ther is no way to do this in the builder or with css?
Not in the Builder, no. Sure, you can use CSS—but the rows are still included in the HTML; they’re just not visible.
On the repeater loop:
%root%:not(:first-child) {
display: none;
}
With the PHP snippet, they aren’t rendered in the first place (the clean solution).
Thanks Ill get back to you on this
The previous selector only works when the first repeater row is also the first child of its parent. The alternative is:
%root% ~ %root% {
display: none;
}
This hides every repeater row that follows another row of the same loop, keeping the first one visible even when other elements precede it. Keep the query loop enabled on that Div.
The remaining rows are still present in the HTML, just hidden. To prevent them from rendering, use the PHP snippet above.
Thanks for the explanation!
