3

I'm fairly new in using ACF so I used the code that was displayed in their site to display what is inside of my repeater field.

However, when I try to show the repeater's content it is empty?? This is my code, this is still in trial mode just to see if it's working-which it isn't. My repeater field already has 2 rows but it's not showing up any of those and just displays the else:

// check if the repeater field has rows of data
if( have_rows('map_infogrp') ):

    // loop through the rows of data
    while ( have_rows('map_infogrp') ) : the_row();

        // display a sub field value
        the_sub_field('google_map');
        the_sub_field('branch_name');
        //$street = get_sub_field('street');
        //$district = get_sub_field('district');
        //$phonenum = get_sub_field('phone_number');
        //$email = get_sub_field('email');


    endwhile;
else:

echo 'why is this empty???';

endif;
Amiel M
  • 57
  • 1
  • 8

2 Answers2

5

You need to specify the page id that you have set the ACF Repeater, otherwise it will get from the current page ID

have_rows($field_name, $post_id); //syntax

So, update your loop inserting the page ID you've entered the repeater data:

if( have_rows('map_infogrp', 'page_id') ):

    // loop through the rows of data
        while ( have_rows('map_infogrp', 'page_id') ) : the_row();

...
caiovisk
  • 3,667
  • 1
  • 12
  • 18
0

If you have the fields filled in on the specific page it should be showing up. If not, double check the field name(not label) that you used. If you have more than one row make sure you're printing it out as an array too

Marwan Fikrat
  • 137
  • 1
  • 8
  • the website is a one pager site but the different parts is divided into different pages, will that be in conflict with the code or not? – Amiel M Feb 07 '18 at 03:03
  • yes every page has it's own fields you need to fill out. Otherwise you can get the options plugin to have a global storage. Maybe var_dump the subfield and see what comes out? – Marwan Fikrat Feb 07 '18 at 03:07
  • i think the problem is each page was created in wp, not in the backend so it's hard for me to place a php code for it unless it's in shortcode. – Amiel M Feb 07 '18 at 03:12