Home › Forums › Front-end Issues › Extracting Post Object data from within a Repeater › Reply To: 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; ?>
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.