3

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;
?>  
Prabin Parajuli
  • 551
  • 2
  • 12
  • 37
Ekin
  • 43
  • 1
  • 6

1 Answers1

0

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 }  ?>
Aibrean
  • 6,297
  • 1
  • 22
  • 38
  • 1
    Thank you Aibrean, but it is working in single.php, it is not working in archive.php, i mean in categories page, it doesn't get the repeater data from any post. For example, i have a post and it has repeater fields. In category page, i can't get the data of repeater fields of that post. – Ekin Nov 05 '15 at 15:56
  • Are you putting it in the loop for that post? – Aibrean Nov 05 '15 at 16:06