Support

Account

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;   
    }