Home Forums ACF PRO How do repeater and relationships work together


How do repeater and relationships work together

  • Hi. I really like the ACF and has just bought the pro.

    I’m trying to get the repeater and relationships to work together.
    But do not get it.

    The page I use to test me out on:



    Sub: – this is ok 🙂 but I don’t anderstand how to make the design or

  • resultat_r1_poang

    // check if the repeater field has rows of data
    if( have_rows('resultat_2015_r1') ):
     	// loop through the rows of data
        while ( have_rows('resultat_2015_r1') ) : the_row();
            // display a sub field value
    else :
        // no rows found
  • That looks right so far, you just need to build a nested loop inside your while loop to display the posts from the relationship field

  • Thanks. I have tested all the examples on the page and also a relationship that I have on another page without repeaters. But I get no work. This is how my last attempt looks.

    <?php if( have_rows('resultat_2015_r1') ): ?>
    	<ul class="slides">
    	<?php while( have_rows('resultat_2015_r1') ): the_row(); 
    		// vars
    		$image = get_sub_field('image');
    		$content = get_sub_field('content');
    		$link = get_sub_field('link');
    						*  Query posts for a relationship value.
    						*  This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
    						$forare = get_posts(array(
    							'post_type' => 'forare',
    							'meta_query' => array(
    									'key' => 'tavlingsforare_post', // name of custom field
    									'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
    									'compare' => 'LIKE'
    						<?php if( $forare ): ?>
    							<?php foreach( $forare as $forare ): ?>
    									<a href="<?php echo get_permalink( $forare->ID ); ?>">
    										<?php echo get_the_title( $forare->ID ); ?>
    							<?php endforeach; ?>
    						<?php endif; 
    		<li class="slide">
    			<?php if( $link ): ?>
    				<a href="<?php echo $link; ?>">
    			<?php endif; ?>
    				<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
    			<?php if( $link ): ?> 
    			<?php endif; ?>
    		    <?php echo $content; ?> innehåll - tavlingsforare_post
    	<?php endwhile; ?>
    <?php endif; ?>
  • I’m not sure what you’re doing here, but you said that one of the fields is a relationship field, a relationship field returns the list of posts that are selected. If you’re getting a relationship field why are you doing a query to get posts?

  • Sorry, do not have a clue.
    I’m not so good at this so deep encoding so I have more or less just cut in and tested all possible variants without really understanding what I do.

    I would like to do the following


    It is a result list.

    First I want to retrieve a user if there is one.
    If not, I want to retrieve a relationship that is a custom post type named forare (drivers).

    Then I want to get the results that are sub fields and that’s just the ones I’ve got it right. 🙂

  • Viewing 5 posts - 1 through 5 (of 5 total)

    The topic ‘How do repeater and relationships work together’ is closed to new replies.