Support

Account

Home Forums General Issues Relationship fields within repeater fields

Solved

Relationship fields within repeater fields

    • rdck

    • August 20, 2013 at 5:20 am

    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
        }
      }
    }
    



    • rdck

    • August 20, 2013 at 7:41 am

    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;?>	
    • rdck

    • August 30, 2013 at 6:31 pm

    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?

    • Elliot

    • September 2, 2013 at 12:52 pm

    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)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.