Skip to content

Instantly share code, notes, and snippets.

@wplit
Last active May 1, 2026 03:18
Show Gist options
  • Select an option

  • Save wplit/493c3ce8ba8db4d68ba313aa3229b241 to your computer and use it in GitHub Desktop.

Select an option

Save wplit/493c3ce8ba8db4d68ba313aa3229b241 to your computer and use it in GitHub Desktop.
Example looping through an 'event' post type, and then an acf repeater 'event_repeater' inside each event
<?php
function my_get_calendar_events() {
// Custom post type slug
$post_type = 'event';
// ACF field names (post-level)
$field_color = 'event_color';
$field_start = 'event_start_date';
$field_end = 'event_end_date';
// Repeater field name
$repeater_field = 'event_repeater';
// Repeater sub-fields
$repeater_start = 'event_repeater_start_date';
$repeater_end = 'event_repeater_end_date';
$events = array();
$posts = get_posts( array(
'post_type' => $post_type,
'posts_per_page' => -1,
'post_status' => 'publish',
) );
// Loop through posts
foreach ( $posts as $post ) {
$title = get_the_title( $post->ID );
$url = get_permalink( $post->ID );
$color = get_field( $field_color, $post->ID );
// Event data from posts
$start = get_field( $field_start, $post->ID );
if ( $start ) {
$events[] = array(
'id' => $post->ID,
'title' => $title,
'start' => $start,
'end' => get_field( $field_end, $post->ID ) ?: '',
'color' => $color ?: '',
'url' => $url,
);
}
// Repeater events
$rows = get_field( $repeater_field, $post->ID );
if ( $rows ) {
foreach ( $rows as $index => $row ) {
if ( empty( $row[ $repeater_start ] ) ) {
continue;
}
// Event data from repeater
$events[] = array(
'id' => $post->ID . '_' . $index,
'title' => $title,
'start' => $row[ $repeater_start ],
'end' => $row[ $repeater_end ] ?: '',
'color' => $color ?: '',
'url' => $url,
);
}
}
}
return $events;
}
// Whitelist for {echo:} dynamic tag.
add_filter( 'bricks/code/echo_function_names', function( $names ) {
$names[] = 'my_get_calendar_events';
return $names;
} );
@wplit

wplit commented May 1, 2026

Copy link
Copy Markdown
Author

Now it'll be looping through all the posts and the repeater wthin each post, producing the array of events, something like this..

[
{
"id": 15069,
"title": "Art Exhibition",
"start": "2026-05-07",
"end": "2026-05-07 01:00:00",
"color": "#3788d8",
"url": "https://some-website.com"
},
{
"id": 15069,
"title": "Art Exhibition",
"start": "2026-05-12",
"end": "2026-05-15",
"color": "#3788d8",
"url": "https://some-website.com"
},
{
"id": 15069,
"title": "Art Exhibition",
"start": "2026-05-29",
"end": "2026-05-31",
"color": "#3788d8",
"url": "https://some-website.com"
},
{
"id": 15069,
"title": "Business Networking",
"start": "2026-04-13",
"end": "2026-04-13 01:00:00",
"color": "#3788d8",
"url": "https://some-different-website.com"
},
]

Use Bricks' echo function to add the array to the query loop

CleanShot 2026-05-01 at 12 16 58@2x

@wplit

wplit commented May 1, 2026

Copy link
Copy Markdown
Author

Then you'd grab the values from each item in the loop using Bricks' query_array dynamic tag

{query_array @key:'title'}
{query_array @key:'start'}
{query_array @key:'color'}

See Bricks' docs for more examples of how to get data from array - https://academy.bricksbuilder.io/article/query-loop/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment