Home › Forums › Add-ons › Repeater Field › Display Posts from sub-post Repeater Field
I am having a hard time with something and hoping I can get a little assistance. Here is my goal:
I have a web site where we put on multiple Events in various locations which inlcude Artist Instructors (primarily musicians) which change every year. We want to be able to provide a page where someone can go and see who taught at each location/year combo. Or to filter the list. I believe I need to do the following to make this work:
So Iam trying to create a Template for the Main Page. I can pull the appropriate Overview Post, but I am not getting the Artist Posts (Biographies) to display. I get the Title as a link for the First of Three in the list. After that I get 23 listings with no Title/Link and only the text for teh custom field with no entry (actually a foreach error but that is likely because some other data is being returned). Any idea where I may be off on this?
Code:
<?php
/**
* The template for displaying the primary festival location pages
*
* Template Name: Festival Main
*
* @package WordPress
* @subpackage Boxwood\\
* @since Twenty Twelve 1.0
*/
get_header();
?>
<div id="container">
<div id="content">
<div id="main-column-full-width">
<?php /* The entry content */ ?>
<div class="entry-content">
<?php if(!is_front_page()) {?>
<?php if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
} ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php }?>
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
the_content();
endwhile;
endif;
?>
<h1>Start Latest</h1>
<?php
/**
* Get the Overview Post to pull data for retrieving other posts, etc
*/
$my_location = get_field('location_location');
$my_year = get_field('year');
$startyear = $my_year . '0000';
$endyear = $my_year + 1 . '0000';
$args = array(
'numberposts' => -1,
'post_type' => 'post',
'category_name' => 'festival-overview',
'meta_query' => array(
array(
'key' => 'location',
'value' => $my_location,
),
array(
'key' => 'start_date',
'value' => $startyear,
'compare' => '>'
),
array(
'key' => 'start_date',
'value' => $endyear,
'compare' => '<'
)
)
);
$overview_posts = new WP_Query( $args );
// Show the Overview Post content
if ( $overview_posts->have_posts() ) :
while ( $overview_posts->have_posts() ) :
$overview_posts->the_post();
// Check rows exists.
if( have_rows('artists') ):
// Loop through rows.
while( have_rows('artists') ) : the_row();
// Load sub field value.
$featured_posts = get_sub_field('artist');
if( $featured_posts ): ?>
<ul>
<?php foreach( $featured_posts as $post ):
// Setup this post for WP functions (variable must be named $post).
setup_postdata($post); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<span>A custom field from this post:
<?php
$my_instrumentsarray = get_field('intruments');
foreach ($my_instrumentsarray as $my_instrument) {
echo $my_instrument ;
} ?>
</span>
</li>
<?php endforeach; ?>
</ul>
<?php
// Reset the global post object so that the rest of the page works correctly.
// wp_reset_postdata();
endif;
endwhile;
endif;
endwhile;
while ( $overview_posts->have_posts() ) :
$overview_posts->the_post();
if ( has_post_thumbnail() ) :
the_post_thumbnail();
endif;
?>
<div class="entry-content">
<?php the_content(); ?>
</div>
</article>
<?php
endwhile;
endif;
// Restore original post data.
wp_reset_postdata();
?>
</div><!-- .entry-content -->
</div><!-- #main-column-full-width -->
</div>
</div><!-- #container -->
<?php get_footer(); ?>
Try using
$overview_posts->reset_postdata();
To reset postdata after your featured posts loop. You currently have that line commented out and using the wrong function.
You must be logged in to reply to this topic.
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.