Home Forums Add-ons Repeater Field Relationship in repeater field


Relationship in repeater field

  • Hello guys !

    I’m following this tutorial and I try to apply it to my website.

    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 ?


    Here is the code for the place : single-place.php

    	function allow_wildcards( $where ) {global $wpdb;
    	$where = str_replace("meta_key = "representation_%", "meta_key LIKE }representation_%",
    	);return $where;}
    	add_filter('posts_where', 'allow_wildcards');
    	$query = new WP_Query(array('post_type' => 'artiste',
        'meta_query' => 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();?>
            		<?php $date_rep = get_sub_field('date_representation');?>
    			<?php echo $date_rep; ?> <?php the_title();?>	
    		<?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:

    1. Query ALL of the posts that could be related
    2. Loop over the posts
    3. Loop over the repeater and find the row that matches
    4. If a match is found add the Post ID to a list (array) of matching post IDs
    5. Alter the query by setting the “post_in” argument for WP_Query()

    This will likely have a significant impact on performance of the page.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.