• Hi Roland
    i have multiselect checkbox in my custom template page.
    how to get labels (or “value titles”) of options?

    for example:
    New Mexico::NM, California::CA, Maine::ME, Arizona::AZ

    how to get “New Mexico” or “Arizona”?
    (get those that have been checked)

    thank you in advance

    • This topic was modified 5 years, 6 months ago by masoud_wp.
    • This topic was modified 5 years, 6 months ago by masoud_wp.
    • This topic was modified 5 years, 6 months ago by masoud_wp.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author xnau webdesign

    (@xnau)

    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>
    Thread Starter masoud_wp

    (@masoud_wp)

    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

    Plugin Author xnau webdesign

    (@xnau)

    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.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Get Labels of Options’ is closed to new replies.