Support

Account

Home Forums General Issues Not showing content of Repeater Field

Solving

Not showing content of Repeater Field

  • Hi, Im trying to make a slide gallery using the repeater field and an image type as subfiled, I have this;

    <?php
    
    $bkg_slide_gallery =  get_field('bkg_slide_gallery', 'option');
    
    echo $bkg_slide_gallery;
    var_dump($bkg_slide_gallery);
    // check if the repeater field has rows of data
    if( have_rows('bkg_slide_gallery') ):
    
     	// loop through the rows of data
        while ( have_rows('bkg_slide_gallery') ) : the_row();
    
            // display a sub field value
            echo the_sub_field('image');
    
        endwhile;
    
    else :
    
        echo "nada que mostrar"; // no rows found
    
    endif;
    
    ?>

    The var_dump show me data inside the array, but in the loop is like if it was empty…

    Arrayarray(3) { [0]=> array(1) { [“image”]=> string(62) “http://www.1stheme.dev/wp-content/uploads/2011/07/img_8399.jpg&#8221; } [1]=> array(1) { [“image”]=> string(69) “http://www.1stheme.dev/wp-content/uploads/2012/07/manhattansummer.jpg&#8221; } [2]=> array(1) { [“image”]=> string(62) “http://www.1stheme.dev/wp-content/uploads/2011/07/dsc04563.jpg&#8221; } }

    Is the first time I use it, but I’ve spent some time trying to make it work without success.

    Thanks

  • Hi,

    if you use the_sub_field() echo is not necessary.
    Is image a text field or an image field?

  • Hi Oliver, the subfield is an image type field, and yes, probably I added that echo trying options but it’s the same, there is nothing showing up without echo too.

    I read a ticket from yesterday in the ACF PRO support forums and it seem that maybe Elliot is trying to fix something related with this?

    Not sure, sorry because I add this post in General Forum and now I can’t change from forum (I think).

    Thank you Oliver for your reply anyway…

  • ok, when it’s an image field, try the following

    while ( have_rows('bkg_slide_gallery') ) : the_row();
    
        $image = get_sub_field('image');
        echo '<img src="'. $image['url'] .'" />';
    
    endwhile;
  • The same, no errors, but no output.
    The thing is that I’m using ACF pro with other filed types without problems, in the loop and as options page. I’ve just buy it to use the repeater field, and I followed the official reference here (http://www.advancedcustomfields.com/resources/repeater/) but is NOT working, and I need help with this.

    I’m using WordPress 4.0 and the las versión of ACF Pro.

    Im using it in header.php after body tag:

    <!doctype html>
    <html class="no-js" <?php language_attributes(); ?> >
    	<head>
    		<!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]-->
    		<meta charset="utf-8" />
    		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
    		<title><?php wp_title( '|', true, 'right' ); ?></title>		
    		<link rel="icon" href="<?php echo get_stylesheet_directory_uri() ; ?>/assets/img/icons/favicon.ico" type="image/x-icon">
    		<link rel="apple-touch-icon-precomposed" sizes="144x144" href="<?php echo get_stylesheet_directory_uri() ; ?>/assets/img/icons/apple-touch-icon-144x144-precomposed.png">
    		<link rel="apple-touch-icon-precomposed" sizes="114x114" href="<?php echo get_stylesheet_directory_uri() ; ?>/assets/img/icons/apple-touch-icon-114x114-precomposed.png">
    		<link rel="apple-touch-icon-precomposed" sizes="72x72" href="<?php echo get_stylesheet_directory_uri() ; ?>/assets/img/icons/apple-touch-icon-72x72-precomposed.png">
    
    <?php wp_head(); ?>
    
    	<?php Short_head_styles(); ?>
    	<?php /* ACF - Options Page */ require_once('header-custom-styles.php');?>
    
    	<script type="text/javascript">
    	// SLIDE NAVIGATION
    		$(function() {
    	  $('a[href*=#]:not([href=#])').click(function() {
    	    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
    	      var target = $(this.hash);
    	      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
    	      if (target.length) {
    	        $('html,body').animate({
    	          scrollTop: target.offset().top
    	        }, 1000);
    	        return false;
    	      }
    	    }
    	  });
    	});
    	</script>
    	</head>
    
    	<body <?php body_class(); ?> id="home">
    
    <section id="main-container" class="container" role="document">
    <style type="">
    	#nav-menu{background: rgba(0,0,0,0.5);width:100%;}
    </style>
    <div id="nav-menu">
    	<div class="row"><?php CGrid_top_bar(); ?></div>
    </div>
    		<script>
    		      var navigation = responsiveNav(".nav-collapse", {
    		        animate: true,                    // Boolean: Use CSS3 transitions, true or false
    		        transition: 284,                  // Integer: Speed of the transition, in milliseconds
    		        label: "Menu",                    // String: Label for the navigation toggle
    		        insert: "after",                  // String: Insert the toggle before or after the navigation
    		        customToggle: "",                 // Selector: Specify the ID of a custom toggle
    		        closeOnNavClick: false,           // Boolean: Close the navigation when one of the links are clicked
    		        openPos: "relative",              // String: Position of the opened nav, relative or static
    		        navClass: "nav-collapse",         // String: Default CSS class. If changed, you need to edit the CSS too!
    		        navActiveClass: "js-nav-active",  // String: Class that is added to <html> element when nav is active
    		        jsClass: "js",                    // String: 'JS enabled' class which is added to <html> element
    		        init: function(){},               // Function: Init callback
    		        open: function(){},               // Function: Open callback
    		        close: function(){}               // Function: Close callback
    		      });
    	    </script>
    <!-- Ressponsive Nav Menu End -->
    
    	<?php // youtube video
        if 	( is_front_page() && $bkg_vid_online) {
    	require_once('video-bkgs.php');
    	} ?>
    
    <?php 
    
    // $bkg_slide_gallery =  get_field('bkg_slide_gallery', 'option');
    
    // echo $bkg_slide_gallery;
    // var_dump($bkg_slide_gallery);
    // check if the repeater field has rows of data
    if( have_rows('bkg_slide_gallery') ):
    
     	// loop through the rows of data
    	while ( have_rows('bkg_slide_gallery') ) : the_row();
    
    	    $image = get_sub_field('image');
    	    echo '<img src="'. $image['url'] .'" />';
    
    	endwhile;
    
    else :
    
        echo "nada que mostrar"; // no rows found
    
    endif;
    
     ?>
    
  • When createing the image type field you can choose the return value – what did you choose there?

  • Hi Oliver, I solve this needing with other plugin. If the next time I find the same problem (maybe I was doing somthing wrong ¿?) I wil open a new ticket. Thanks.

  • <?php 
    $images = get_field(‘bkg_slide_gallery’, 'option');
    if( $images ): ?>
    <ul class="clearfix row">
    <?php foreach( $images as $image ): ?>
    <li>
    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
    <p><?php echo $image['caption']; ?></p>
    </li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>
Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Not showing content of Repeater Field’ is closed to new replies.