WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: Custom Field Template] output of checkboxes (4 posts)

  1. mael
    Member
    Posted 5 years ago #

    Using checkboxes like in the example :
    [Favorite Fruits]
    type = checkbox
    value = apple # orange # banana # grape
    default = orange # grape

    I try do display the selected items, but only the first checked one (for instance "apple") appears in html.
    I call the field like this :
    <?php echo get_post_meta($post->ID, 'Favorite Fruits', true); ?>
    something wrong ?
    (I'm not a php guy, only html/css and wp template tags...)
    Thanks !

  2. mael
    Member
    Posted 4 years ago #

    Found !
    The array can be returned with "get_post_custom_values".
    I used this within the loop :

    <?php  $mykey_values = get_post_custom_values('Your-Key-Here');
    foreach ( $mykey_values as $key => $value ) {
    echo "<li class=\"A -Class-Name\"> $value</li>";
    } ?>

    I hope it can help Everyone :) !

  3. knivesOut
    Member
    Posted 4 years ago #

    thx!

  4. amp343
    Member
    Posted 4 years ago #

    You could also try

    <?php echo get_post_meta($post->ID, 'Favorite Fruits', false); ?>

    ...with the last argument FALSE instead of true. That argument tells the function whether or not to return a single value.

Topic Closed

This topic has been closed to new replies.

About this Topic