I'm working with ACF in WordPress.
I have a custom post type called Projects
. Within there the user has the option to upload 2 featured images through an ACF repeater field.
Now, on the home page I've given the user the option to select 8 Post Object's from the Projects post type.
I need to be able to loop through this home page repeater field, and pull out both featured images and the project title from each 'project' post object.
ACF has recently depreciated the repeater_field
function which I think it throwing me off here.
But, here's what I've been trying to work with so far:
<!-- check for repeater field -->
<?php if(get_field('featured-projects')): ?>
<?php while(has_sub_field('featured-projects')): ?>
<!-- get project post objects -->
<?php $projects = get_sub_field('project'); ?>
<!-- without the loop below, this echo's all 8 projects ID's -->
<?php echo($projects->ID); ?><br />
<!-- when added, only pulls the first project. And limits the echo above to the first ID -->
<?php $loop = new WP_Query( array(
'post_type' => 'projects',
'p' => $projects->ID
) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endwhile; ?>
<?php endwhile; ?>
<?php endif; ?>
I've tried to comment the code, but if anything does't make sense, let me know.