Support

Account

Home Forums Add-ons Repeater Field Repeater field returns nothing from a Template Reply To: Repeater field returns nothing from a Template

  • You’re not being difficult. What I’m trying to say is that the problems that your seeing in this template that you’re trying to create are a symptom of a larger issues with the template where it’s included. I’m not sure if it’s a nesting problem, if you’re main loop is starting in the wrong place or if you are trying to get values from somewhere other than the post that the page is for. But until you get the problems with the template for Template Name: Niche Page Template corrected you will not be able to get the other template problem fixed.

    Putting aside the template that you originally posted about and looking at the template field where it is included.

    This is your code from the template. I have made it a bit easier for myself to read and I’ve added plenty of comments where there are problems with its flow and nesting.

    
    <?php
      /**
      Template Name: Niche Page Template
      */
      get_header();
        ?>
          <section id="PageContainer"><!-- this section no matchin close tag -->
            <!-- 
              the_field() function call below is not in the loop
              $post_id must be supplied
              if you are getting this value from a specific post
              then you should specify that posts ID
              if you are getting this value from the current post
              then this should be inside "The Loop"
              Please see below for where "The Loop" Begins
            -->
            <section style="background-image:url(<?php the_field("niche_header_banner_image"); ?>); 
                  background-size:cover; background-repeat:no-repeat;" id="NicheHeaderImage">
              <h1 id="NicheH1" class="MaxWidth"><?php the_field("niche_header_title");?></h1>
            </section>
            <section id="BannerHeaderSec" class="MaxWidth">
              <!-- 
                the_field() function call below is not in the loop
              -->
              <a href="<?php 
                    the_field("horizontal_banner_ad_url"); ?>"><img src="<?php 
                    the_field("horizontal_header_banner_ad_image"); ?>" alt=""/></a>
            </section>
            <section id="NicheSearchForm" class="col-lg-12">
              <section id="NicheSearchFormContent" class="MaxWidth"> 
                <!-- 
                  the_field() function call below is not in the loop
                --> 
                <h2 id="NicheSearchH2" class="text-center"> <?php the_field("SearchForTitle");?> </h2>
                <section id="SearchBoxNiche"> <?php get_search_form(); ?></section>
              </section><!--NicheSearchFormContent-->
            </section><!--NicheSearchForm-->  
            <article class="MaxWidth">
              <section id="NicheSideNav" class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
                <?php 
                  // the loop that is run in the included template should be basee
                  // on something other than the main WP Qeury
                  // let's comment this out until we get the rest of this template
                  // straighened out
                  //load_template( 'wp-content/themes/modestclothes/SideBarNav.php' );
                ?>
              </section><!--NicheSideNav-->
              <section id="3SqureImagesSec" class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
                <section id="NicheSquareAd1" class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                  <?php    
                    // ***************
                    // none of the get_field() calls in this if/else block are in "The Loop" 
                    // ***************    
                    if (get_field("niche_square_ad_1_url") && get_field("niche_square_ad_1_image")) { 
                      echo '<a href="'.
                            get_field("niche_square_ad_1_url").
                            '"><img src="'.
                            get_field("niche_square_ad_1_image").
                            '" alt=""/></a>';
                    } else {
                      echo '<a href="'.
                            get_field("square_request_ad_image_default_url").
                            '"><img src="'.get_field("square_request_ad_image_default").
                            '" alt=""/></a>';
                    }
                  ?>
                </section>
                <section id="NicheSquareAd2" class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                  <?php    
                    // ***************
                    // none of the get_field() calls in this if/else block are in "The Loop" 
                    // ***************           
                    if(get_field("niche_square_ad_2_url") && get_field("niche_square_ad_2_image")) { 
                      echo '<a href="'.
                            get_field("niche_square_ad_2_url").
                            '"><img src="'.
                            get_field("niche_square_ad_2_image").
                            '" alt=""/></a>';
                    } else {
                      echo '<a href="'.
                            get_field("square_request_ad_image_default_url").
                            '"><img src="'.get_field("square_request_ad_image_default").
                            '" alt=""/></a>';
                    }
                  ?>
                </section>
                <section id="NicheSquareAd3" class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                  <?php     
                    // ***************
                    // none of the get_field() calls in this if/else block are in "The Loop" 
                    // ***************                 
                    if(get_field("niche_square_ad_3_url") && get_field("niche_square_ad_3_image")) { 
                      echo '<a href="'.
                            get_field("niche_square_ad_3_url").
                            '"><img src="'.
                            get_field("niche_square_ad_3_image").
                            '" alt=""/></a>';
                    } else {
                      echo '<a href="'.
                            get_field("square_request_ad_image_default_url").
                            '"><img src="'.
                            get_field("square_request_ad_image_default").
                            '" alt=""/></a>';
                    }
                  ?>
                </section>
                <section class="ListsContainer col-xs-12">
                  <div id="SampleContent" role="main">
                  <!-- 
                      ************************************************************************
                      ************************************************************************
                      the following while is the start of "The Loop" 
                      ************************************************************************
                      ************************************************************************
                  -->
                  <?php while ( have_posts() ) : the_post(); ?>
                  <?php 
                    // check for rows (parent repeater)
                    // *****
                    // this have_rows in in the loop, 
                    // it uses the post ID of the curren post
                    // in The Loop
                    // the same is true of all other ACF function calls untill
                    // we get to the end of the loop
                    if( have_rows('links_list') ): 
                      ?>
                        <div id="to-do-lists">
                          <?php 
                            // loop through rows (parent repeater)
                            while( have_rows('links_list') ): the_row(); 
                              ?>
                                <div>
                                  <h2 class="ListHeader">
                                    <?php the_sub_field('links_list_header'); ?>
                                  </h2>
                                  <?php 
                                    // check for rows (sub repeater)
                                    if( have_rows('links_list_items') ): 
                                      ?>
                                        <ul>
                                          <?php 
                                            // loop through rows (sub repeater)
                                            while( have_rows('links_list_items') ): the_row();
                                              // display each item as a list - 
                                              // with a class of completed ( if completed )
                                              ?>
                                                <li class="CategoryListLinks">
                                                  <a class="CategoryListLinksURL" href="<?php 
                                                      the_sub_field('link_url'); ?>"><?php 
                                                      the_sub_field('link_name'); ?></a>
                                                  </br>
                                                  <?php the_sub_field('category_description'); ?>
                                                </li>
                                              <?php 
                                            endwhile; // end of while( have_rows('links_list_items') )
                                          ?>
                                        </ul>
                                      <?php 
                                    endif; //if( get_sub_field('items') ): 
                                  ?>
                                </div>  
                              <?php 
                            endwhile; // while( has_sub_field('to-do_lists') ): 
                          ?>
                        </div>
                      <?php
                    endif; // if( get_field('to-do_lists') ): 
                  ?>
                  <!-- 
                        This endwhile is the end of "The Loop"
                        It is already marked as the end of the loop
                  --> 
                  <?php endwhile; // end of the loop. ?>
                  </div><!-- #SampleContent -->
                </section><!--ListsContainer--> 
              </section><!--3SquareImagesSec-->
            </article>
            <div id="content" class="site-content"><!-- This div does not have a matching </div> -->
              <div id="primary" class="content-area">
                <main id="main" class="site-main" role="main">
                  <?php get_sidebar(); ?> 
                </main><!-- #main -->
              </div><!-- #primary -->
              <script>  
                // Sets interval...what is transition slide speed?
                $('#myCarousel2').carousel({
                interval: 3000
                });
              </script>
        <?php 
      get_footer();
    ?>