Support

Account

Home Forums Add-ons Repeater Field Using Post Object in Nested Repeater

Helping

Using Post Object in Nested Repeater

  • I’m using the Repeater and Post Objects to get related products on a WooCommerce single-product.php page. I can render everything outside of my repeater loop just fine. This issue comes in when I try to render the subfields from my repeater loop, which should be showing fields (which are <li>) that are filled out in the related product.

    Here is my current code:

    <?php 	
        $post_objects = get_field('related_products');
        if( $post_objects ): ?>	
         <div class="related-products">
           <h3><?php the_field('related_post_title'); ?></h3>
    	<?php foreach( $post_objects as $post_object): ?>
             <div class="pricing-card w-full pricing-left cursor-pointer max-w-xs bg-black flex flex-col justify-start m-1 py-8 p-4 relative md:max-w-lg md:px-12 lg:w-1/3 lg:px-4 shadow-xl">
    	 <div class="my-0 mx-auto">
    	 <img src="<?php echo get_field('product_image', $post_object->ID)['url']; ?>" class="mx-auto"/>
    	</div>
    	<h4 class="text-center text-white my-5">
            <?php echo get_the_title($post_object->ID) ?> • <?php echo 
            get_field('tier_price', $post_object->ID);?></h4>
    	<div class="pricing-ul text-white text-base h-full pr-4 leading-normal text-gray-100">
    	<ul class="pricing-ul text-white text-base h-full pr-4 leading-normal text-gray-100 mb-8 pl-12">
    	<?php if( have_rows('offering') ){ 
    		while ( have_rows('offering') ) { the_row(); 
    		   if( have_rows('offering_info') ){
    		     while ( have_rows('offering_info') ) { the_row(); ?>
    	               <li class="bullet" style="list-style-image: url(<?php echo get_sub_field('offering_image')['url']; ?>)">
    	                <span class="font-nomal text-base leading-relaxed"><?php echo get_sub_field('offering_text'); ?></span></li>
    	<?php
    		}
    	    }
    	}
        }?>
       </div>
       <div class="flex justify-center items-center">
    	<a href=" <?php echo get_permalink(); ?>" class="btn bg-gray-300 py-2 my-0 mr-1 uppercase shadow-md text-xs">SEE DETAILS</a>
    	<?php $product = wc_get_product(get_the_ID());
    	      $color = get_field('color');
    	      echo '<a href="'.$product->add_to_cart_url().'"class="btn py-2 my-0 ml-1 uppercase shadow-md text-xs" style="background-color: '.$color.' ">ADD TO CART</a>'; ?>
      </div>
      <div class="colored-bottom w-full h-3 absolute bottom-0 left-0" style="background-color:<?php echo get_field('color');?>"></div>
      </div>
      <?php endforeach; ?>
        </ul>
        </div>
        <?php endif; ?>

    I’m not sure how to use the post object to render the information that’s in the repeater.

  • You need to supply the post ID in have_rows() the same way that you using it in get_field(). You only need to do this for the top level repeater and it is not required in the nested repeater.

    
    if( have_rows('offering', $post_object->ID) ){ 
    		while ( have_rows('offering', $post_object->ID) ) { the_row(); 
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.