Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom field who's content I would like to output as a ul list.

The custom field contains words that are separated with a spaces between.

I'm trying to use this code here but it's not working.

    <?php
    $list_items = get_post_meta($post->ID, 'idid');

         if($list_items){
            $list_items = explode(" ", $list_items) {
                echo '<ul>';
                    foreach($list_items as $list_item)
                        echo '<li>' . $list_item . '</li>';
                echo '</ul>';
            }
        }

    ?>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You are using get_post_meta incorrectly. As you use it, it will return an array - you cannot explode an array. See the codex on get_post_meta();

If you pass true as the third parameter, this tells the function to return a string. So,

$list_items = get_post_meta($post->ID, 'idid', true);

should work.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.