0

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>';
            }
        }

    ?>
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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