Home › Forums › Feature Requests › Query by dropdown field label › Reply To: Query by dropdown field label
Hi @ageibert
I believe you can get the label and value pairs with the get_field_object() function. So you can do it like this:
$the_input = '12'; // The input from users
// Get the select field object
$select_object = get_field_object('select_field_name');
// Search the field value based on the label
$userInput = array_search($the_input, $select_object['choices']);
print_r($userInput);
I hope this helps 🙂
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 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.