Sorry if this is posted elsewhere, but i’m having a hard time finding the answer.
I have my ACF repeater data. One data set simply has a name field, while another has 3 fields.
I know there is the query builder, but how do i use it within HTML to display the proper fields?
My repeater field name is “alternative names” with the name sub field
in Laravel, I’d have something like
@ foreach($alt_names as $altname)
{{$altname->name}}
@endforeach
I did get this from chatGPT since i don’t really know Wordpress’s way of structuring things.
<?php
$names = '';
if( have_rows('your_repeater_field_name') ):
while( have_rows('your_repeater_field_name') ) : the_row();
$name = get_sub_field('name');
if (!empty($name)) {
$names .= $name . ', ';
}
endwhile;
$names = rtrim($names, ', '); // remove the last comma and space
endif;
echo $names;
?>
But I have no clue where to add this result to bricks or WordPress in general.
For the multiple field sets, I need to display the data in a table.
Ive been able to create a static table with the rich text block, but I’m not sure how to loop the rows based on the query builder or custom code. The rich text editor doesnt seem to accept PHP. And the query builder would add the table headings for each row. I’m not sure how to only loop the
You can structure it how you like, this is just one example.
SECTION->CONTAINER
On the container add query. In TYPE choose your repeater set.
You can’t add dynamic data to code - yet. So to build a table will be fiddly. If it’s good enough, you can have a pseudo table.
Set container to flex, row. Inside container add basic text. Inside basic text choose the ACF field from the repeater.
Now you can add a series of TEXT blocks and give them borders / widths etc. to create a table.
If it has to be a proper html table, you’d have to write the function. E.g.
function my_function() {
$names = '<table><tr>';
if( have_rows('your_repeater_field_name') ):
while( have_rows('your_repeater_field_name') ) : the_row();
$name = get_sub_field('name');
if (!empty($name)) {
$names .= '<td>' . $name . '</td>';
}
endwhile;
$names .= '</tr></table>';
endif;
return $names;
Notice - I add the opening table tags, and closing. Also I RETURN $names, not just echo it.
This will create a one-row table with loads of columns… not very good. You will have to decide how many rows you will have - and then put a
count + 1
if count = 3 $names .='</tr><tr>'; $count = 1;
Sort of counter in…
So it would add in a new row every 3 names.
Finally - where you want the table, you would add {echo:my_function} - which in bricks runs that function - the return would then populate with the table data.
This is why I’d choose the pseudo columns - just style some basic text elements and add your field to them in a query loop.
Hope that helps 
Thanks, I did manage to make the code block work. I thought it would just display my code but to execute I needed to toggle a switch. And that may only be toggable if you set permissions in settings page.
I’ll still have to test some things I’m sure. Just made a comma separated list so far.
Ill try your method too once i get to the tables section if the code block fails to work