-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple phone numbers on one page results in only the last number being output #10
Comments
Never mind! If I convert the value to an array before calling in the second field, it works. Thanks! Example for other idiots like me: $phone_number = get_field("phone_number", "theme");
$phone_number = $phone_number ? $phone_number->toArray() : false;
$fax_number = get_field("fax_number", "theme");
$fax_number = $fax_number ? $fax_number->toArray() : false; |
Just spent a few minutes trying to get this to work automatically with |
I'll think about a better approach to fix these problems. |
@Log1x running in to this issue again, in a $phone_numbers = get_field("phone_numbers", "options");
foreach ($phone_numbers as $data) {
$phone_number = $data["phone_number"]->toArray();
echo "<pre>";
print_r($phone_number);
echo "</pre>";
} This is resulting in every every loop outputting the last value in the array... doesn't make a ton of sense to me. EDIT: Also just tried in a |
Looking through the code, I think the problem is that it's implemented as a "singleton," which to my understanding only one instance can exist on a page at once. |
Made some progress, but I'm not a fan of this solution. $phone_numbers = get_field("phone_numbers", "theme");
/**
* Hack to prevent the last phone number always being used
*/
use Log1x\AcfPhoneNumber\PhoneNumber;
foreach ($phone_numbers as $key => $data) {
if ($raw = get_option("theme_phone_numbers_{$key}_phone_number")) {
$parsed = new PhoneNumber($raw);
$phone_numbers[$key]["phone_number"] = $parsed->toArray();
} else {
$phone_numbers[$key]["phone_number"] = null;
}
}
foreach ($phone_numbers as $data) {
echo $data["phone_number"]->e164;
} By accessing the values outside of ACF, I can get each instance individually and convert it, rather than each instance being generated in the repeater and stored in an array (which results in only the last instance being accessible). The drawback is that this retrieves the same value from the database twice for each number, and the code is... sloppy. I feel like there's got to be a better solution, maybe if I tie in to the |
are you on the latest version? I didn't think this should be an issue anymore since #17 |
I thought I was, but I'll double check and report back. |
Yep, you were right 🤦♂️ Thanks, I should've checked that a lot sooner, my bad. It's been a long week 😅 |
With multiple phone numbers set, it seems that only the last phone number can be output. In the example below, assuming "+13128675309" is set to
$phone_number
and "+13128675310" is set to$fax_number
, bothecho
s will output "+13128675310".This has only been tested when installed without composer, per #8.
Am I doing this incorrectly, or is this a bug?
The text was updated successfully, but these errors were encountered: