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
http://support.advancedcustomfields.com/forums/topic/using-options-page-fields-in-functions-php/
since the repeater field i created is from an option not a custom field.
Hi @alexgold05
If your code is within the functions.php file, it need to run AFTER the init action.
Thanks
E