WordPress.org

Forums

WP Easy Post Types
Select Lists are displaying empty values? (7 posts)

  1. eitai2001
    Member
    Posted 4 years ago #

    Hi Guys.

    I created a custom field with a select list and I entered values. When I go to the custom post type and add new content, the dropdown list shows blank values, but if I look at the source code, the values are defined in there ... they're just not visible.

    I'm running the standard wordpress admin theme, so I have no idea what the issue is?

    Just to give you an idea of the code being generated:

    <div class="field-phone_os field-phone_os">
                <span class="label">Operating System</span>
    <select name="phone_os">
            <option  value="Android 1.5 Cupcake"></option>
            <option  value="Android 1.6 Donut"></option>
            <option  value="Android 2.1 Eclair"></option>
            <option  value="Android 2.2 Froyo"></option>
            <option  value="Android 3.0 Gingerbread"></option>
        </select>
    
            </div>

    Regards

    Itai

    http://wordpress.org/extend/plugins/easy-post-types/

  2. mchampa
    Member
    Posted 4 years ago #

    Hi Itai,
    I have the same problem. I was able to change one line of code in the plug-in, and the select drop down now displays values and text in the select control. This seems like the wrong thing to do, but works in the interim until someone can explain how this should properly work.

    In the file /classes/custom-select/theme-select-input.php, line 7,

    <option <?php print $option['selected']; ?> value="<?php print $option['key']; ?>"><?php print $option['value']; ?></option>

    I changed the second value to key
    <option <?php print $option['selected']; ?> value="<?php print $option['key']; ?>"><?php print $option['key']; ?></option>

  3. itst
    Member
    Posted 4 years ago #

    You need to input the list in a [key]|[value] format like this:

    1|Monday
    2|Tuesday
    3|Wednesday
    4|Thursday
    5|Friday
    6|Saturday
    7|Sunday

    This would render as

    <option value="1">Monday</option>
    <option value="2">Tuesday</option>
    ... and so on.

    Hope this helps.

    BTW, the logic can be found in easy-post-types/classes/custom-select/custom-select.php in the function prepareArray().

    If you want to use PHP the generate the list, your code needs to return an array like this:

    return array(
       array(1, 'Monday'),
       array(2, 'Tuesday'),
       ... and so on.
    );
  4. mchampa
    Member
    Posted 4 years ago #

    Perfect...thanks Itst for clarifying. Very much appreciated.

  5. eitai2001
    Member
    Posted 4 years ago #

    Thanks Itst :)

  6. secci
    Member
    Posted 4 years ago #

    cheers itst! been wondering that for months!

  7. a2d
    Member
    Posted 4 years ago #

    Seems to be a few ways to display the selected value in a template.
    With a custom select field called weekday, with the label "Day" and content:
    1|Monday
    2|Tuesday
    3|Wednesday
    4|Thursday
    5|Friday
    6|Saturday
    7|Sunday

    The "snippit" way:
    <?php the_ept_field('weekday'); ?>
    Displays e.g. Day Monday

    or:
    <?php echo get_ept_field('weekday'); ?>
    Displays e.g. Day Monday

    To just get the value so you can use your own label then you'd think you could use:
    <?php echo get_ept_field('weekday',array('raw' => 'true')); ?>
    or alternatively:
    <?php echo get_post_meta($post->ID,'weekday',true) ?>
    But both these display 1 (the value of the select option rather than the text of the option)

    How can you just get the text? I can remove the label e.g.
    <?php echo preg_replace('/Day/','',get_ept_field('weekday'),1); ?>

    But there must be an easier way?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Easy Post Types
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic