Home Forums Add-ons Repeater Field Repeating Post Object


Repeating Post Object

  • I’m hoping someone can 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. I am trying to pull in the custom fields to 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); ?>
    					//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">
    				<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(); ?>
    		<?php endif; ?>
    	<?php endwhile; ?>
    <?php endif; ?>
  • Hi @blondeskee

    Could you please tell me what’s wrong with the code? Could you please share the current result of the code and how you want it to be?

    Also, could you please share the JSON export file of your field group so I can check your setup and test it on my installation?

    Thanks 🙂

  • Hey James,

    I figured it out. I didn’t need the foreach and I needed to set $post = $featured_icons;.


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

The topic ‘Repeating Post Object’ is closed to new replies.