Search code examples
wordpressrepeateradvanced-custom-fields

Advanced Custom Fields Sub_Field in Archive Page


I am using ACF plugin with repeater addon in Wordpress, Normally in archive.php I can use get_field or the_field functions and these are showing posts' data. (ex: title)

In single.php there is no problem, When i want to use the_sub_field or get_sub_field in archive.php,

Image of Repeater Field Name

In archive.php, the example below shows me No word. How can I see the Yes word? What should I do? Thank you.

<?php
    if( have_rows('add_content') ):
        echo "Yes";
    else :
        echo "No";
    endif;
?>  

Solution

  • You need an if/while statement for a repeater to work.

     <?php if (have_rows('add_content')){ ?>
         <?php while (have_rows('add_content')) { the_row(); ?>
            Yes
         <?php } // while:   ?>
     <?php } else { ?>
           No
     <?php }  ?>