Support

Account

Home Forums ACF PRO have_rows() not working

Solving

have_rows() not working

  • Hi there,
    I am using acf pro version 5.2.2

    I made a simple Flexible Content Field named ‘travel_gallery’ it contains 2 rows: ‘travel_text_row’ and ‘travel_photo_row’

    But if I output the fields content following theses instructions nothing appears at all: http://www.advancedcustomfields.com/resources/flexible-content/
    It just prints ‘no layouts found’

    What I am doing wrong?

    If I output <?php print_r( get_field('travel_gallery') ); ?>

    I get the content: Array ( [0] => travel_text_row [1] => travel_photo_row )

    <?php
    
    // check if the flexible content field has rows of data
    if( have_rows('travel_gallery') ):
    
         // loop through the rows of data
        while ( have_rows('travel_gallery') ) : the_row();
    
            if( get_row_layout() == 'travel_text_row' ):
    
              the_sub_field('travel_text');
    
            elseif( get_row_layout() == 'travel_photo_row' ): 
    
              the_sub_field('travel_photo');
    
            endif;
    
        endwhile;
    
    else :
    
        // no layouts found
      echo 'no layouts found';
    
    endif;
    
    ?>
  • just to get sure:
    you check frontpage for a page/post/custom-post where you have some content filled at backend. either photo or text.

    <?php
    
    // check if the flexible content field has rows of data
    if( have_rows('travel_gallery') ):
    
         // loop through the rows of data
        while ( have_rows('travel_gallery') ) : the_row();
    
            if( get_row_layout() == 'travel_text_row' ){
              $get_travel_text = get_sub_field('travel_text');
              echo $get_travel_text;
              echo '<br>normally above should stand the text';
            }
    
            if( get_row_layout() == 'travel_photo_row' ){ 
              $get_travel_photo = get_sub_field('travel_photo');
              echo $get_travel_photo;
              echo '<br>normally above should come the image';
            }
    
        endwhile;
    
    else :
    
        // no layouts found
      echo 'no layouts found';
    
    endif;
    
    ?>

    your code look correct. but what is the result when you use mine instead?

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

The topic ‘have_rows() not working’ is closed to new replies.