Support

Account

Home Forums General Issues Relationship fields within repeater fields

Solved

Relationship fields within repeater fields

  • Hi folks,

    Having a slight problem I can’t seem to figure out (even with a good old var_dump)…

    I have a simple repeater set up as a custom field, with two relationship fields set up within the repeater. See screenshots below for set up.

    What I’m looking to do is query this repeater and then query the information from each of the relationship field values.

    This is what my code currently looks like…`<?php var_dump( get_field('primary_and_secondary_selector') ); ?>

    <?php $posts = get_field('primary_and_secondary_selector'); if ( $posts ) : ?>
    <ul>
    <?php foreach ( $posts as $post_object) : ?>
    <li><span>Primary <?php the_field('primary', $post_object->ID); ?></span></li>
    <li><span>Secondary <?php the_field('secondary', $post_object->ID); ?></span></li>
    <?php endforeach; ?>
    </ul>
    <?php wp_reset_postdata(); ?>
    <?php endif; ?>`

    This was just a test to see if I could at least grab anything back, but alas it did not. The pages in the relationship query have the image field supplementary_logo which I want to return.

    So to be clear — I want to query the data of the primary and secondary pages that are selected from the repeater field, both of which are in a repeater field.

    My dump brings back this —

    
    		
    	
    	array(2) {
      ["primary"]=>
      array(1) {
        [0]=>
        object(WP_Post)#119 (25) {
          ["ID"]=>
          int(81)
          ["post_author"]=>
          string(1) "1"
          ["post_date"]=>
          string(19) "2013-08-16 16:09:08"
          ["post_date_gmt"]=>
          string(19) "2013-08-16 16:09:08"
          ["post_content"]=>
          string(0) ""
          ["post_title"]=>
          string(13) "FishVet Group"
          ["post_excerpt"]=>
          string(0) ""
          ["post_status"]=>
          string(7) "publish"
          ["comment_status"]=>
          string(4) "open"
          ["ping_status"]=>
          string(4) "open"
          ["post_password"]=>
          string(0) ""
          ["post_name"]=>
          string(13) "fishvet-group"
          ["to_ping"]=>
          string(0) ""
          ["pinged"]=>
          string(0) ""
          ["post_modified"]=>
          string(19) "2013-08-19 17:20:11"
          ["post_modified_gmt"]=>
          string(19) "2013-08-19 17:20:11"
          ["post_content_filtered"]=>
          string(0) ""
          ["post_parent"]=>
          int(18)
          ["guid"]=>
          string(84) "http://bmk.screenformat.com/bmk-group/wp/bmkholdings.com/bmkholdings.com/?page_id=81"
          ["menu_order"]=>
          int(4)
          ["post_type"]=>
          string(4) "page"
          ["post_mime_type"]=>
          string(0) ""
          ["comment_count"]=>
          string(1) "0"
          ["filter"]=>
          string(3) "raw"
          ["format_content"]=>
          NULL
        }
      }
      ["secondary"]=>
      array(3) {
        [0]=>
        object(WP_Post)#285 (25) {
          ["ID"]=>
          int(135)
          ["post_author"]=>
          string(1) "1"
          ["post_date"]=>
          string(19) "2013-08-19 15:59:09"
          ["post_date_gmt"]=>
          string(19) "2013-08-19 15:59:09"
          ["post_content"]=>
          string(0) ""
          ["post_title"]=>
          string(22) "FishVet Group (Norway)"
          ["post_excerpt"]=>
          string(0) ""
          ["post_status"]=>
          string(7) "publish"
          ["comment_status"]=>
          string(4) "open"
          ["ping_status"]=>
          string(4) "open"
          ["post_password"]=>
          string(0) ""
          ["post_name"]=>
          string(20) "fishvet-group-norway"
          ["to_ping"]=>
          string(0) ""
          ["pinged"]=>
          string(0) ""
          ["post_modified"]=>
          string(19) "2013-08-19 16:01:11"
          ["post_modified_gmt"]=>
          string(19) "2013-08-19 16:01:11"
          ["post_content_filtered"]=>
          string(0) ""
          ["post_parent"]=>
          int(81)
          ["guid"]=>
          string(85) "http://bmk.screenformat.com/bmk-group/wp/bmkholdings.com/bmkholdings.com/?page_id=135"
          ["menu_order"]=>
          int(1)
          ["post_type"]=>
          string(4) "page"
          ["post_mime_type"]=>
          string(0) ""
          ["comment_count"]=>
          string(1) "0"
          ["filter"]=>
          string(3) "raw"
          ["format_content"]=>
          NULL
        }
        [1]=>
        object(WP_Post)#284 (25) {
          ["ID"]=>
          int(138)
          ["post_author"]=>
          string(1) "1"
          ["post_date"]=>
          string(19) "2013-08-19 15:59:25"
          ["post_date_gmt"]=>
          string(19) "2013-08-19 15:59:25"
          ["post_content"]=>
          string(0) ""
          ["post_title"]=>
          string(20) "FishVet Group (Asia)"
          ["post_excerpt"]=>
          string(0) ""
          ["post_status"]=>
          string(7) "publish"
          ["comment_status"]=>
          string(4) "open"
          ["ping_status"]=>
          string(4) "open"
          ["post_password"]=>
          string(0) ""
          ["post_name"]=>
          string(18) "fishvet-group-asia"
          ["to_ping"]=>
          string(0) ""
          ["pinged"]=>
          string(0) ""
          ["post_modified"]=>
          string(19) "2013-08-19 16:01:22"
          ["post_modified_gmt"]=>
          string(19) "2013-08-19 16:01:22"
          ["post_content_filtered"]=>
          string(0) ""
          ["post_parent"]=>
          int(81)
          ["guid"]=>
          string(85) "http://bmk.screenformat.com/bmk-group/wp/bmkholdings.com/bmkholdings.com/?page_id=138"
          ["menu_order"]=>
          int(2)
          ["post_type"]=>
          string(4) "page"
          ["post_mime_type"]=>
          string(0) ""
          ["comment_count"]=>
          string(1) "0"
          ["filter"]=>
          string(3) "raw"
          ["format_content"]=>
          NULL
        }
        [2]=>
        object(WP_Post)#111 (25) {
          ["ID"]=>
          int(142)
          ["post_author"]=>
          string(1) "1"
          ["post_date"]=>
          string(19) "2013-08-19 15:59:52"
          ["post_date_gmt"]=>
          string(19) "2013-08-19 15:59:52"
          ["post_content"]=>
          string(0) ""
          ["post_title"]=>
          string(19) "FishVet Group (Inc)"
          ["post_excerpt"]=>
          string(0) ""
          ["post_status"]=>
          string(7) "publish"
          ["comment_status"]=>
          string(4) "open"
          ["ping_status"]=>
          string(4) "open"
          ["post_password"]=>
          string(0) ""
          ["post_name"]=>
          string(17) "fishvet-group-inc"
          ["to_ping"]=>
          string(0) ""
          ["pinged"]=>
          string(0) ""
          ["post_modified"]=>
          string(19) "2013-08-19 16:01:29"
          ["post_modified_gmt"]=>
          string(19) "2013-08-19 16:01:29"
          ["post_content_filtered"]=>
          string(0) ""
          ["post_parent"]=>
          int(81)
          ["guid"]=>
          string(85) "http://bmk.screenformat.com/bmk-group/wp/bmkholdings.com/bmkholdings.com/?page_id=142"
          ["menu_order"]=>
          int(3)
          ["post_type"]=>
          string(4) "page"
          ["post_mime_type"]=>
          string(0) ""
          ["comment_count"]=>
          string(1) "0"
          ["filter"]=>
          string(3) "raw"
          ["format_content"]=>
          NULL
        }
      }
    }
    



  • I worked it all out. Here is my solution.

    <?php if ( get_field('primary_and_secondary_selector') ) : ?>
     
    	<?php while ( has_sub_field('primary_and_secondary_selector') ) : ?>
    	
    	<div class="grid_3">
    	
    		<?php $primary_queries = get_sub_field('primary'); ?>
    		<?php if ( $primary_queries ) : ?>
    		
    			<?php foreach( $primary_queries as $primary_query ) : ?>
     
    				<?php echo wp_get_attachment_image(get_field('supplementary_logo', $primary_query->ID), 'medium' ); ?>
     
    			<?php endforeach; ?>
    			
    		<?php wp_reset_postdata(); ?>
    		<?php endif;?>
    		
    		<?php $secondary_queries = get_sub_field('secondary'); ?>
    		<?php if ( $secondary_queries ) : ?>
    		<ul>
    		<?php foreach( $secondary_queries as $secondary_query ) : ?>
     
    			<li><?php echo wp_get_attachment_image(get_field('supplementary_logo', $secondary_query->ID), 'medium' ); ?></li>
     
    		<?php endforeach; ?>
    		</ul>
    			
    		<?php wp_reset_postdata(); ?>
    		<?php endif;?>
    		
    		</div>
     
    	<?php endwhile; ?>
    
    	<?php endif;?>	
  • Quick question — why would this return each repeater on the page; but if I query the page from another template, for example

    <?php $animal_health = new WP_Query('post_type=page&p=126'); while ( $animal_health->have_posts() ) : $animal_health->the_post(); ?>

    it would only bring back one repeater… not all?

  • Hi @rdck

    Sorry, I don’t quite understand what you mean by it would only bring back one repeater… not all?

    Can you explain the issue with more clarity? What are you expecting and what do you get instead?

    Thanks
    E

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

The topic ‘Relationship fields within repeater fields’ is closed to new replies.