Support

Account

Home Forums Add-ons Repeater Field Display Posts from sub-post Repeater Field

Helping

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:

    • Have a Primary “Festival” page which has some information which can be over-written each year. Include metadata via ACF for the Location (A Clone field from the Overview post below so I do not have to edit Locations in multiple places) and the current Year (date picker formatted as YYYY only) we are registering people for.
    • Have a Post for each Artist wich is a Biography and includes an ACF field for their “Instrument”
    • Have an Overview Post which includes detailed information for teh current Year and a Repeater field for selecting Post Objects for the Biographies. I am using the Repeater field so we can set the Order in which the Biographies appear. This Overview post has ACF fields for
    • Location
    • Start Date (date picker)
    • End Date (date picker)
    • Artists (Repeater with a Post Object Subfield called Artist)
    • 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.

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

You must be logged in to reply to this topic.