Home Forums Add-ons Repeater Field Repeater Field in functions.php


Repeater Field in functions.php

  • I’m trying to populate an array through the repeater field however this is not related to the issue.

    If i put the following code (from the documentation)

    $rows = get_field('repeaterfieldname','option');
    foreach($rows as $row)
    		echo '<li>sub_field_1 = ' . $row['field_name'] . ', sub_field_2 = ' . $row['field_description'] .', etc</li>';

    I get the following error Warning: Invalid argument supplied for foreach(), however if i put the same code into file header.php everything works, but i need that code to be in functions.php how can i fix this? Am i missing something ?

  • Is it within a loop? Don’t think get_field will work unless it’s within a loop?

    Test it by doing print_r($rows) before foreach, see what you get

  • It doesn’t need to be in a loop. I found out the issue is related to this

    since the repeater field i created is from an option not a custom field.

    • Elliot

    • September 14, 2013 at 1:14 pm

    Hi @alexgold05

    If your code is within the functions.php file, it need to run AFTER the init action.


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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.