I believe you’ll have to declare $lunch as a global variable, i.e.
global $lunch = get_group('lunch');
I have tried that but get error message.
Hmmm…
I have also been told (in a very rude way) that this foreach($lunch as $lunch) make no sense at all, and it may be so but it still works in my template and does the job.
As surely everybody understands im a total novice when it comes to this. I have made some “custom fields” in backend and want to show them on my page, frontend, sorry for my bad english, and it works without no problems at all when i use that code in a template.
How would u write it in proper way?
Ah, yes, I should have noticed that before. foreach($lunch as $lunch) is not correct. This might help clarify how foreach loops should be structured
You can’t declare the same variable in foreach(){}. If that worked for you previously, you were very lucky. Try something like this:
<?php
$lunch_ary = get_group('lunch');
foreach ($lunch_ary as $lunch) {
echo '<span class="lunch-dag">' . $lunch['lunch_dag'][1]. '</span><br />';
echo '<span class="lunch-matratt">' . $lunch['lunch_matratt'][1]."<br />";
echo $lunch['lunch_matratt'][2]."<br />";
echo $lunch['lunch_matratt'][3]."<br />";
echo $lunch['lunch_matratt'][4]. '</span><br /><br />';
}
?>
If the above doesn’t work, then we must start digging. What is this get_group() function? Is it globally accessible?
EDIT: is this code supposed to loop? Your code makes me wonder if the echo statements are meant to only be executed once…
EDIT: is this code supposed to loop? Your code makes me wonder if the echo statements are meant to only be executed once…
Maybe that is what the
foreach($lunch as $lunch)
is about, will only process the first item in the array, stepping to the 2nd item probably fails.
I think that:
$lunch_ary = get_group('lunch');
print_r($lunch_ary);
is called for.