Support

Account

Home Forums Reply To:

  • I’ve created a group (called ‘ce_hours’). It has 3 subfields (lt, nav, lvtlvp) all of which are numbers.

    This is my code for viewing the the array:

    if ( have_rows('ce_hours') ){
        echo '<h2>there are rows in the hours</h2>';
        echo '<pre>'.print_r(ce_hours).'</pre>';
    }else {
        echo 'no rows';
    }

    If I load this on a page before adding the fields then it echo’s no rows. However if I save the page then the field holds rows and my print_r states “1”.

    I’ve tried to test this by having a page open and going to my acf dashboard and copying my group (ce_hours to ce_hours_copy).

    I then add this to my page content:

    if ( have_rows('ce_hours_copy') ){
        echo '<h2>there are rows in the hours copy</h2>';
        echo '<pre>'.print_r(ce_hours_copy).'</pre>';
    }else {
        echo 'no rows';
    }

    If I reload the page then I get “there are rows in the hours”

    1

    “.
    Now if I edit the page and click update (no other changes) then when I reload that page again I get
    “there are rows in the hours”

    1

    “.
    “there are rows in the hours copy”

    1

    “.

    SO for some reason it’s adding rows even though I don’t want it to. In the end I want to add a title if there are any rows, so I need the conditional to work. Here is my prod code I intend to use:

    if ( have_rows('ce_hours') ){
        echo '<h2>Credit Hours</h2>';
        while ( have_rows ('ce_hours') ) : the_row();        
                echo '<ul>';
                if (get_sub_field('rn_hours')) echo '<li>'.get_sub_field('rn_hours').' credit hours for RNs</li>';
                if (get_sub_field('nab_hours')) echo '<li>'.get_sub_field('nab_hours').' credit hours for NABs</li>';
                if (get_sub_field('lvnlpn_hours')) echo '<li>'.get_sub_field('lvnlpn_hours').' credit hours for LVN/LPNs</li>';
                echo '</ul>';
        endwhile;
    }