Home Forums General Issues Getting ACF Select field Label for a given Value


Getting ACF Select field Label for a given Value

    • muppix

    • January 13, 2021 at 1:08 am

    I’ve written a function that uses SQL to give me a count of the distinct values of bl-project.ptype, where bl-project is a custom taxonomy and ptype is an ACF select field containing value : label pairs. The function works well, but returns values for ptype and I’d prefer labels.

    There are a couple of similar threads on this topic but the solutions therein don’t seem to work unless you’re on a post detail page, whereas I need a value -> label lookup function that works independent of a post or taxonomy.*

    So far I’m getting around this by maintaining a lookup function in PHP which takes the select value as input and returns the label value as output, but maintaining this function in parallel with the ACF Select field is a recipe for disaster. Thinking that I could adapt my original SQL function to incorporate a lookup I did a search for one of my select field values, and the only place it appears in the WP DB is in the wp_posts entry which appears to describe my ACF Select field, and I can’t work out the format in which it’s stored.

    As always, many thanks in advance for any assistance.

    * Incidentally, get_field_object() doesn’t seem to work on select fields against a custom taxonomy, only those against a custom post type. Not sure if this is intentional.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.