Home › Forums › Add-ons › Repeater Field › 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); ?>
<?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; ?>

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;.
Thanks!
Jennifer
The topic ‘Repeating Post Object’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.