If you are in a shortcode template, you can use the template helper class. To print the value title, use the print_value method. For example:
<?php $record = new PDb_Template($this); ?>
<p>The value is: <?php $record->print_value('fieldname'); ?>.<?p>
yes but i want the label of it, not value
Consider the following example (in multiselect checkbox)
Western States::optgroup, New Mexico::NM, California::CA, Maine::ME, Arizona::AZ
In your code:
<p>The value is: <?php $record->print_value(‘fieldname’); ?>.<?p>
output is
The value is: CA
but i want (output):
The label is: California
also i want optgroup label
for example (output):
The group is : Western States
It does work, I just tested it, so there may be something in the field options configuration that is leading to a different result than you expect. Also, check the record values in the database directly (using phpMyAdmin) so you know exactly what that record value is trying to index.
To get the title of the optgroup that your value is in is more difficult, you’ll need a bit of code for that. Take a look at this gist for an idea how to do that.
https://gist.github.com/xnau/a1acbd83071341989cd3f8e0d1cbd2f9
Note that this won’t work with a multi-select type field, you’ll have to modify the code to deal with the fact that the saved value will be an array of values.