Support

Account

Home Forums Front-end Issues Extracting Post Object data from within a Repeater

Solved

Extracting Post Object data from within a Repeater

  • Hi Jonathon,

    I was hoping you could help me with an issue I’m having. I created a custom post type with custom fields. I then created a custom field that lives on the home page that is a repeating field with a post object field. This way you can select the posts you want to display on the home page.

    <?php if( have_rows('home-cta-icons') ): ?>
    
    	<?php while( have_rows('home-cta-icons') ): the_row(); 
    		// Set Variables
    		$featured_icons = get_sub_field("featured-icon");
    	?>
    		<?php if($featured_icons) : ?>			
    
    			<section class="icon-brick content-link brick">
    				<?php foreach( $featured_icons as $post): ?>
    				<?php setup_postdata($post); ?>
    				<?php
    					//Set Custom Field Variables
    					$icon_cta_icon = get_field( 'icon-cta-icon');
    					$icon_cta_link = get_field( 'icon-cta-link');
    					$icon_cta_text = get_field( 'icon-cta-button-text');
    				?>
    
    				<div class="icon-container">
    					<img src="<?php echo esc_url( $icon_cta_icon ); ?>" alt="" class="icon">
    				</div>
    				<h3><?php the_title(); ?></h3>
    				<a href="<?php echo esc_url( $icon_cta_link ); ?>" class="button"><?php echo  esc_html( $icon_cta_text ); ?></a>		
    			
    				<?php endforeach; ?>
    				<?php wp_reset_postdata(); ?>
    			</section>	
    
    		<?php endif; ?>
    	<?php endwhile; ?>
    <?php endif; ?>
Viewing 26 post (of 26 total)

The topic ‘Extracting Post Object data from within a Repeater’ is closed to new replies.