Home › Forums › Add-ons › Repeater Field › Relationship in repeater field
Hello guys !
I’m following this tutorial and I try to apply it to my website.
https://www.advancedcustomfields.com/resources/querying-relationship-fields/
I have artists thats plays in places.
An artist can play in different places, so i want to compare the row of the repeater field with the current place ID. And only show the row where the place is the same that the page.
But i don’t know how to achieve it…
Anyone can help me ?
Thanks
Here is the code for the place : single-place.php
<?php
function allow_wildcards( $where ) {global $wpdb;
$where = str_replace("meta_key = "representation_%", "meta_key LIKE }representation_%",
$wpdb->remove_placeholder_escape($where)
);return $where;}
add_filter('posts_where', 'allow_wildcards');
?>
<?php
$query = new WP_Query(array('post_type' => 'artiste',
'meta_query' => array(
array(
'meta_key' => 'representation_%_lieu_representation',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE',
)
)
));
?>
<?php if($query->have_posts()) : while ($query->have_posts() ) : $query->the_post();?>
<?php if( have_rows('representation') ): while( have_rows('representation') ) : the_row();?>
<p>
<?php $date_rep = get_sub_field('date_representation');?>
<?php echo $date_rep; ?> <?php the_title();?>
</p>
<?php endwhile; else : endif; ?>
<?php endwhile; else: endif; wp_reset_postdata();?>
You cannot follow that tutorial when the relationship field is a sub field of a repeater.
You would have to:
This will likely have a significant impact on performance of the page.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.