Support

Account

Home Forums Add-ons Repeater Field get_field is empty

Solved

get_field is empty

  • Hi,

    I have managed to use the repeater field successfully before but just cannot get it working on another site.

    I’m trying to add a Twitter Bootstrap carousel into a page in WordPress (latest version).

    Here’s an extract of some of the code I have in the page template:

    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    			<div id="banner" class="hidden-xs container">
    
    				<div id="carousel-home-page" class="carousel slide">
    				  <ol class="carousel-indicators">
    				    <li data-target="#carousel-home-page" data-slide-to="0" class="active"></li>
    				    <li data-target="#carousel-home-page" data-slide-to="1"></li>
    				    <li data-target="#carousel-home-page" data-slide-to="2"></li>
    				    <li data-target="#carousel-home-page" data-slide-to="3"></li>
    				  </ol>
    
    				  	if(get_field('carousel_items')):
    
    						while(has_sub_field('carousel_items')):
    
    							$image = get_sub_field('carousel_image');
    							$link = get_sub_field('carousel_link');
    							$heading = get_sub_field('carousel_heading');
    							$content = get_sub_field('carousel_text');
    
    							printf('<div class="carousel-inner"><div class="item active"><img src="%s" class="img-responsive"><div class="carousel-caption"><a class="btn btn-primary" data-toggle="button" href="%s">%s</a><p>%s</p></div></div>',$image['url'],$link,$heading,$content);
    
    						endwhile;
    
    					endif;
    				?>
    
    				  <a class="left carousel-control" href="#carousel-home-page" data-slide="prev">
    				   	<span class="icon-prev"></span>
    				  </a>
    				  <a class="right carousel-control" href="#carousel-home-page" data-slide="next">
    				   	<span class="icon-next"></span>
    				  </a>
    				</div>
    			</div> <!-- #banner.hidden-xs -->

    I’ve checked the field names over and over again and they are definitely right but get_field(‘carousel_items’) is not returning anything.

    Can you help?

    Thank you,
    Elizabeth

  • Maybe I’m not seeing it, but looks like you’re missing a opening php tag <?php in front of the if(get_field(‘carousel_items’)):

  • Thanks Nuro. The opening tag was there but I hadn’t copied it in.

    Anyway, I seem to have solved this problem now. I hadn’t switched on debugging mode and when I did a few errors came up – one about automatic feed links and another about how I had enqueued jquery. I’ve sorted these out and now get_field() is working.

    I now have another issue where I can’t add more than one item in my repeater field (which I had been able to before) but if I can’t sort that out I’ll start up another topic.

    Thanks again,
    Elizabeth

  • Actually, I’m not convinced that the errors on debugging were the problem as I’ve noticed I had the same code in the site that I have got working.

    I noticed that the custom field information I’d put in before had disappeared and thought this may have happened when I reinstalled the Advanced Custom Fields plugin and so reentered the first item and then it worked. I did this at the same time as correcting the errors in functions.php. Now I think it wasn’t working before because the data had been deleted.

    However, I can now only enter one set of custom field information (so, only one carousel item) in Chrome. If I try to add another set then it takes ages trying to save the changes but never gets anywhere. If I use Firefox I can add a second carousel item in with no problem.

    I don’t know if these problems are related.

  • Have you tried setting the repeater image to table? Then upload all images at once and the repeater should automatically add a row for each image.

  • Hello.

    Yes that works. I also removed an item called carousel_order that I wasn’t using in the PHP code and I think this may have been causing some problems too.

    Thanks.

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

The topic ‘get_field is empty’ is closed to new replies.