Home Forums Add-ons Repeater Field Accessing Post Object in a Nested Repeater


Accessing Post Object in a Nested Repeater

  • I have been reading the forums and StackOverflow all day long trying to figure this out.

    I have attached a screenshot of a mockup of the table (labeled), how it looks live, and what my custom post type looks like in the back-end.

    What I am trying to accomplish is to display the post objects featured image in the table head row. Then I’d like the “legend titles” to display in the first row of the table body and the attributes filling in the rest of the row.

    I am able to get the legend titles and attributes to display fine however I can’t get the post objects featured images to display in the table head. When I play with my code to display the featured image, it only shows 1 (when it should be 5) and the legend tiles and attributes disappear.

    Here is my code:

  • This has been solved. The code is below.

     * The template for displaying all pages
     * Template Name: Feature Comparison
     * @link
     * @package Merchant_Services
    <div id="primary" class="content-area">
    	<main id="main" class="site-main">
        <?php get_template_part( 'template-parts/content','hero' ); ?>
    		<div class="comparison-box-wrapping">
    			<?php $loop = new WP_Query( array( 
    				'post_type'      => 'comparison_tables',
    				'orderby'		     => 'date', 
    				'order'          => 'DESC', 
    				'posts_per_page' => '5') ); 
        	<?php while( $loop->have_posts() ) : $loop->the_post(); ?>
    				<div class="comparison-block">				
    					<div class="recommend-header"><h2 class="green-medium"><?php the_title(); ?></h2></div>				
    									<?php $legends = get_field('legend');
    										foreach($legends as $legend){
    											$company_attributes = $legend['company_attributes'];
    											foreach ($company_attributes as $company_attribute) {
    												$companies = $company_attribute['company'];
    												//limit the count to only get the logos from the first legend
    												if( has_post_thumbnail($companies->ID) && $count < 6) { 
    													echo "<th>";
    														$thumb = get_the_post_thumbnail($companies->ID, 'full');
    														echo $thumb;
    														echo "</th>";     
    									} ; ?>
    							<?php if ( have_rows( 'legend' ) ) : ?>												
    								<?php while( have_rows('legend') ): the_row();
    									$legend_title  = get_sub_field('legend_title');
    										<td><p><?php echo $legend_title; ?></p></td>								
    											<?php while ( have_rows( 'company_attributes' ) ) : the_row(); 
    												$attribute  = get_sub_field('attribute');										
    												<td><?php echo $attribute; ?></td>
    											<?php endwhile; ?>     			
    								<?php endwhile; ?>
    								<?php endif; ?>					     						
    				</div> <!-- comparison-block END -->
    			<?php endwhile; ?>
      	</div> <!-- comparison-box-wrapping END -->
    		<?php get_template_part( 'template-parts/content','disclosure-dark' ); ?>
    	</main><!-- #main -->
    </div><!-- #primary -->
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.