Support

Account

Home Forums General Issues Only Display Custom Field Choices with Posts Reply To: Only Display Custom Field Choices with Posts

  • 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.

    Any suggestions?

    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)