Home › Forums › Front-end Issues › Get option labels without post/user ID › Reply To: Get option labels without post/user ID
Wouldn’t that mean hard coding these field keys into my code?
In the meantime I ended up querying the database like this:
function get_field_label( $field, $value ) {
global $wpdb;
$label = '';
$field = $wpdb->get_col( $wpdb->prepare( "
SELECT post_content FROM {$wpdb->posts}
WHERE post_excerpt = '%s'
AND post_type = 'acf-field'
", $field ) );
if( $field ) {
$options = unserialize( $field[0] );
$choices = $options['choices'];
$label = $choices[$value];
}
return $label;
}
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.