So I don’t understand why this is not working. I’m using WordPress and a plugin called ACF to populate some data. I’m looping through my repeater field to spit out the data like so:
<?php
$links = get_field('footer_links'); // spits out the array
if($links) {
foreach ( $links as $link ) {
$logo = $link['logo'];
$link = $link['link'];
$text = $link['text'];
echo '<div class="link">';
echo ' <a href="'.$link.'"><img src="'.$logo.'" /><p>'.$text.'</p></a>';
echo '</div>';
}
}
// Logo spits out a image path
// link spits out the URL path
// text SHOULD just spit out the title, however throws PHP warning
?>
For the variable $text
I am getting a PHP warning.
Warning: Illegal string offset ‘text’ in…
Why is it that my other variables — $logo
, $link
do not throw this warning? They are created the same way as the other $text
variable.
I’ve tried recreating the entire repeater field and changing the name etc.. with no success.
Here is my print_r($links);
Array
(
[0] Array
(
[logo] http://domainname.com/imagepath
[link] http://.....
[text] Text1
)
[1] Array
(
[logo] http://domainname.com/imagepath
[link] http://.....
[text] Text2
)
[2] Array
(
[logo] http://domainname.com/imagepath
[link] http://.....
[text] Text3
)
)
Error is thrown here:
Array
$link
is lacking index['text']
. It’s because you are overwriting the array variable here:Change that to:
And you’re gold.