I have a Repeater Field Group on an Options Page called “Address Book”. I would like to display the Phone Number (text field), of my first entry, in the WordPress Header.php.
I can’t find any documentation on how to do this.
I found something like this in the support forums but it’s not working.
$rows = get_field(‘location’, ‘option’); // get all the rows
$first_row = $rows; // get the first row
$first_row_phone = $first_row[‘location_phone’ ]; // get the sub field value
<?php echo $first_row_phone; ?>
You are attempting to get the index value of a string here. To explain:
The following code results in an array:
$rows = get_field(‘location’, ‘option’);
Then you are using the 0 index to get the first value of that array, which will result in yet another array, only this time associative:
$first_row = $rows
Finally, you are able to target the actual field you are looking for by it’s field label, in this case ‘location_phone’:
$first_row_phone = $first_row[‘location_phone’ ];
What results from that line of code is the string value you are looking for. By echoing out
echo $first_row_phone; you are confusing PHP into trying to get the index value of a string. So really, all you need to do is echo the string itself:
Long story short, remove the ‘’ from the echo.
That worked. And thanks for the detailed response. Much appreciated.