
I am working on displaying a related repeater by using a custom query.
But I’m only able to retrieve ONE row of the related repeater.
$location_id = get_the_ID();
// filter
function my_posts_where( $where ) {
global $wpdb;
$where = str_replace(
"meta_key = 'list_of_classes_",
"meta_key LIKE 'list_of_classes_",
$wpdb->remove_placeholder_escape($where)
);
return $where;
}
add_filter('posts_where', 'my_posts_where');
$args = array(
'post_type' => 'timetable', // custom post type
'post_status' => 'publish', // show published posts only
'posts_per_page' => -1, // return all of them
'meta_query' => array(
array(
'key' => 'list_of_classes_%_class_what_location', // name of custom field
'value' => '"' . $location_id . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
),
),
);
$timetable = new WP_Query ( $args );
while ( $timetable->have_posts() ): $timetable->the_post();
// check for rows (parent repeater)
if( have_rows('list_of_classes') ) {
// loop through rows (parent repeater)
while( have_rows('list_of_classes') ): the_row(); ?>
<div class="col-md-4">
<?php // get title of class
$classes = get_sub_field('class'); ?>
<?php if ( $classes) { ?>
<?php foreach( $classes as $post):
setup_postdata($post); ?>
<h3><a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php endforeach;
} ?>
<strong><?php the_sub_field('weekday'); ?></strong>
<?php the_sub_field('start_hour'); ?>
<?php the_sub_field('class_length'); ?> minutes
<button class="btn button-<?php the_sub_field('class_status'); ?>"><?php the_sub_field('class_status'); ?></button>
</div>
<?php endwhile; // while( has_sub_field('list_of_classes') ):
} else { ?>
<h3>No Classes Scheduled yet.</h3>
Please check back soon.
<?php }
endwhile;