Support

Account

Home Forums Add-ons Repeater Field Shortcodes break repeater

Solving

Shortcodes break repeater

  • I use repeater fields to display custom content / widgets in different pages. Since I have upgraded to WordPress 3.8 it seems like somehow the ACF plug-in is acting up. Usually I use around 3 rows in my repeater field, and it behaves as following:
    1: If I don’t use shortcodes, the content from all rows will show up
    2: If I use shortcodes in any of the rows, only the first row will show up

    When I disable the content filter under the repeater field all my rows show up, however the shortcodes are obviously not working. What am I missing here? I’m Working on WordPress 3.8.1 and ACF version 3.5.8.2.

    Code that I use on my page:

    <?php 
    /*
    Template Name: What's On
    */
    
    get_header(); 
    
    ?>
    <?php // Background image
    if(get_field('background_page') != "")
    { echo "<div id='wrapper-general' style='background:url(".get_field('background_page').") no-repeat center top #eee' >"; } 
    else {
    // esle, no background image
    echo "<div id='wrapper-general'>"; } ?>
      <div id="wrapper-page" class="container_12">
    
        <div id="header" class="grid_12">
          <?php
          // Local menu
            $walker = new My_Walker;
            wp_nav_menu( array(
              'theme_location' => 'primary',
              'menu' => get_field('sub_menu'),
              'menu_class' => 'sf-menu2',
              'container' => false,
              'walker' => $walker
            ));
          ?>
          <!-- Slider -->
          <?php
          //If slider
          if(get_field('banner_type') == "slider"): ?>
          <div id="slider" class="nivoSlider theme-orman">
            <?php $countiframe = 0; ?>
            <?php while(the_repeater_field('images_slider_page')): ?>
            <?php $countiframe++; ?>
            <?php if(get_sub_field('link_slider_page') != ""): ?>
            <a href="<?php the_sub_field('link_slider_page') ?>" target="<?php the_sub_field('target_slider_page')?>" title="<?php the_sub_field('title_slider_page') ?>"><img src="<?php the_sub_field('image_slider_page') ?>" alt="<?php the_sub_field('title_slider_page') ?>" /></a>
            <?php elseif(get_sub_field('iframe') != ""): ?>
            <a href="<?php the_sub_field('iframe'); ?>" rel="shadowbox;width=940;height=526"><img src="<?php the_sub_field('image_slider_page') ?>" alt="<?php get_sub_field('title_slider_page')?>" /></a>
            <?php else: ?>
            <img src="<?php the_sub_field('image_slider_page') ?>" alt="<?php get_sub_field('title_slider_page')?>" width="940" height="529" />
            <?php endif; ?>
            <?php endwhile; ?>
          </div><!--End slider -->
          
          <?php $countiframe = 0; ?>
          <?php while(the_repeater_field('images_slider_page')): ?>
          <?php $countiframe++; ?>
          <?php if(get_sub_field('iframe') != ""): ?>
          <div id="iframe<?php echo $countiframe ?>" style="display:none;">
            <div style="padding:10px;">
              <?php the_sub_field('iframe') ?>
            </div>
          </div>
          <?php endif; ?>
          <?php endwhile; ?>
          <?php endif; ?>
          <?php 
          // If static image
          if(get_field('banner_type') == "image"): ?>
          <div id="banner"> <img src="<?php the_field('static_image '); ?>"  /> </div>
          <!--End banner -->
          <?php endif; ?>
        </div><!--End header -->
        
     <?php
        // If layout center
        if (get_field('layout_page') == "Center"): ?>
        <?php if (have_posts()) : while (have_posts() ) : the_post(); ?>
          <?php if (get_the_content() != ""): ?>
          <div id="page_content" class="grid_12 alpha">
          <?php the_content(); ?>
          </div><!--End page content -->
          <?php endif; ?>
          <?php endwhile; ?>
        <?php endif; ?>
        
        <div class="clear"></div>
        
        <?php $countiframebox = 0; ?>
        <?php while(the_repeater_field('boxes_page')): ?>
        <?php $countiframebox++; ?>
        <div class="box grid_4">
          
    	  <?php if (get_sub_field('iframe_box_page')): ?>
          <a href="<?php the_sub_field('iframe_video'); ?>" title="" rel="shadowbox;width=940;height=526"><img src="<?php the_sub_field('iframe_picture_box_page'); ?>" alt="<?php the_sub_field('title_iframe_box_page'); ?>" /></a>
      
          <?php else: ?>
          
    	  <?php the_sub_field('box_page'); ?>
          <?php endif; ?>
          
          
        </div>
        <?php endwhile; ?>
        <?php endif; ?>
        
        <?php
        // If layout right
        if (get_field('layout_page') == "Right"): ?>
        <?php if (have_posts()) : while (have_posts() ) : the_post(); ?>
          <?php if (get_the_content() != ""): ?>
          <div id="page_content" class="grid_8 alpha omega">
          
          <?php /* Start What's On content */ ?> 
          
          <h1>At a glance</h1>
          <p>&nbsp;</p>
          <?php the_content(); ?>
          
          
          
          
    <?php global $blog_id; if( $blog_id == '16' ) { ?>
    <div id="events-wrap" class="leeds-base">
    <?php } else if( $blog_id == '9' ) { ?>
    <div id="events-wrap" class="bradford-base">
    <?php } else if( $blog_id == '17' ) { ?>
    <div id="events-wrap" class="belfast-base">
    <?php } else { ?>
    <div id="events-wrap" class="home-base">
    <?php } ?>
    
          
          <?php 
    	  
    	  /*
    global $switched;
        switch_to_blog(1);
        echo 'You switched from blog ' . $switched . ' to 1';
        restore_current_blog();
        echo 'You switched back.';
    	*/
    	
    	
    	  echo do_shortcode("[tf-events-full]"); 
     
    	  ?>
          
    </div>
          
          <?php /* End What's On content */ ?>
          
          
          </div><!--End page content -->
          <?php endif; ?>
          <?php endwhile; ?>
        <?php endif; ?>
        
        <div class="sidebar grid_4">
            
        <?php /*
            <?php $countiframebox = 0; ?>
        <?php while(the_repeater_field('boxes_page')): ?>
        <?php $countiframebox++; ?>
        <div class="box">
          
    	  <?php if (get_sub_field('iframe_box_page')): ?>
          <!--ShadowBox iFrame -->
          <a href="<?php the_sub_field('iframe_video'); ?>" title="" rel="shadowbox;width=940;height=526"><img src="<?php the_sub_field('iframe_picture_box_page'); ?>" alt="<?php the_sub_field('title_iframe_box_page'); ?>" /></a>
          <?php else: ?>
          <?php the_sub_field('box_page'); ?>
          <?php endif; ?>
          
          
        </div>
        <?php endwhile; ?>
    	*/ ?>
        </div><!--End sidebar -->
        <?php endif; ?>
        
        <?php
        // If layout Left
        if (get_field('layout_page') == "Left"): ?>
        <div class="sidebar grid_4">
            <?php $countiframebox = 0; ?>
        <?php while(the_repeater_field('boxes_page')): ?>
        <?php $countiframebox++; ?>
        <div class="box">
          <?php if (get_sub_field('iframe_box_page')): ?>
          <a href="<?php the_sub_field('iframe_video'); ?>" title="" rel="shadowbox;width=940;height=526"><img src="<?php the_sub_field('iframe_picture_box_page'); ?>" alt="<?php the_sub_field('title_iframe_box_page'); ?>" /></a>
          <?php else: ?>
          <?php the_sub_field('box_page'); ?>
          <?php endif; ?>
          
          
        </div>
        <?php endwhile; ?>
        </div><!--End sidebar -->
        
        <?php if (have_posts()) : while (have_posts() ) : the_post(); ?>
          <?php if (get_the_content() != ""): ?>
          <div id="page_content" class="grid_8 alpha omega">
          <?php the_content(); ?>
          </div>
          <?php endif; ?>
          <?php endwhile; ?>
        <?php endif; ?><!--End page content -->
        
        <?php endif; ?>
        
        <?php
        // If no layout
        if (get_field('layout_page') != ""): ?>
        <?php $custom_query = new WP_Query(); 
    while($custom_query->have_posts()) : $custom_query->the_post(); ?>
          <?php if (get_the_content() != ""): ?>
          <div id="page_content" class="grid_12 alpha">
          <?php the_content(); ?>
          </div><!--End page content -->
          <?php endif; ?>
          <?php endwhile; ?>
    <?php wp_reset_postdata(); // reset the query ?>
        <div class="clear"></div>
        <?php endif; ?>
       
    
      
      
      </div><!--End wrapper page -->
    </div> <!--End wrapper general -->
      
      
    
    <?php get_footer(); ?>
  • Hi @sem90

    Sorry to hear you are having troubles after updating WP. It is possible that a change in WP code is not compatible with such an old version of ACF, however, I doubt this is the issue.

    With such a large amount of code dumped above, I am not able to help by pointing out any issues. Perhaps you need to take a step back from the code, and start fresh adding it in line by line until you find the exact problem.

    You mention that there is a filter involved which is causing the issue? What is this filter code?

    Thanks
    E

  • Thanks for reply and apologies for the large chunk of code. I did take large portions of the code out (the entire bit for the slider, the code for counting the boxes). Unfortunately this did not make a difference.

    What I mean by filter, is the option under the ACF field settings, which says: “Run filter “the_content”?. Enabling this filter to use shortcodes within the WYSIWYG field

    As soon as I select ‘No’ all the rows from the repeater fields appear on the website. Obviously this does also mean that my entered shortcodes are now not executed, but they show up as [shortcode] etc. When I enable this filter (so setting on ‘yes’), the shortcodes work. When I now enter normal html data into the rows, they keep working fine.

    The problems begin when I enter a shortcode in any of the rows from my repeater field. Now instead of all rows showing up on the front-end, only the first row is loaded regeardless of it’s content. If I enter a shortcode on the first row, the shortcode works fine and it displays the correct item on the front-end. But as soon as a shortcode in any row of my repeater,no other rows but the first row is loaded on the front-end.

    So the problem somehow seems that shortcodes break the loop after it’s first round – but I can’t figure out why this is happening!

  • Hi @sem90

    Thanks for the clarification. The setting for ‘Run filter “the_content”’ has been removed in v4 as it caused many issues such as the one you are describing.

    Basically, the ‘the_content’ filter should only be run once on a page, and running this multiple times can caused various errors with 3rd party plugins and themes.

    Your options are to upgrade to ACF v4, or disable the option and add this code to your template:

    
    <?php do_shortcode( get_sub_field('wysiwyg_field_name') ); ?>
    

    Thanks
    E

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

The topic ‘Shortcodes break repeater’ is closed to new replies.