Support » Plugin: Block Lab » Select Labels

  • Resolved Elliot Toman

    (@asubtleweb)


    I may be missing something in the documentation, but how can I output the label of a select rather than its value?

    For example, if the select option is
    option_1 : Option One

    …I want to output “Option One,” but block_field( ‘select_name’ ) will only output “option_1.”

    Thanks!

Viewing 1 replies (of 1 total)
  • Plugin Author Luke Carbis

    (@lukecarbis)

    Hey @asubtleweb . Thanks for checking out Block Lab.

    The block_field() and block_value() functions only return the _value_ of a field, which is why they don’t help with the label.

    Instead, you can access the label via the block_field_config() function, which returns all of the settings you’ve assigned to that field.

    
    $select = block_field_config( 'select_name' );
    if ( isset( $select['options'] ) ) {
    	foreach( $select['options'] as $option ) {
    		echo '<li>' . $option['label'] . '</li>';
    	}
    }
    

    Documentation is here: https://github.com/getblocklab/block-lab/wiki/4.-Templating-functions#usage-3

    Hope that helps!

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.