Thanks John. The field allows a single choice only.
Unfortunately, now it’s not displaying anything at all. I think I know why, but I’m not sure how to fix it. In the ACF admin screen where I set up the custom field, under the Choices section, the instructions say:
Enter each choice on a new line.
For more control, you may specify both a value and label like this:
red : Red
blue : Blue
Instead of setting up my choices the way the example shows where the value and the label are the same (red: Red), I set them up so they’re different:
1 : Red
2 : Blue
(Except of course in my case I have it set up for family names (1: Jones, 2: Smith, etc))
I noticed, though, that if I change things so that the choice values and the choice labels are the same, just like they are in the example (i.e. jones : Jones, smith : Smith), then the query we’re working on here works just fine. But if they’re different, then our query draws up an empty list as though no posts are tagged to any of the choices.
The reason I set up the choices with different values & labels is because it allows me to sort & order the choices numerically in other places on my site. It’s worked extremely well up until now & solved a number of other problems I’ve faced in the past. So if possible, I’d like to keep them that way.
Thinking out loud, I wonder if the reason our query draws a blank when the values & labels are different is because it’s searching for the choice values (“1” or “2”) when we need it to be searching for choice labels (“Smith” or “Jones”). The reason I say that is because when I hard-code in one of the values into our array, the query works just fine for that one value. But if I hard-code in one of the labels, then it doesn’t.
Is there a way to add further specification to this part of our query so it targets the choice value instead of the choice label?
array( 'key' => 'family_name', 'value' => $family )
If it looks more specifically for $family->label instead of just $family, maybe that might solve the issue??? ($family->label doesn’t actually work of course; not sure what the syntax would be for that)
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We've just released ACF 5.12.3 with a security fix to prevent arbitrary file uploads to forms with ACF fields.— Advanced Custom Fields (@wp_acf) July 14, 2022
Now that we've released this update, we recommend updating your sites as soon as possible.
© 2022 Advanced Custom Fields.