By wp user frontend I add some checkboxes to users frontend profile. When I use echo get_the_author_meta('my_pet', $author_id) output is:

cat| dog| hamster

And when I use this loop code

$pet = get_user_meta($author_id, 'my_pet');
if( $pet ) {
    foreach( $pet as $pets ) {
        echo $pets;

Outoput is same.
I want display values one by one, and after each of them display a paragraph about it. like this:

some text for cat

some text for dog

some text for hamster

HTML source of checkboxes is:

<label><input type="checkbox" class="wpuf_my_pet_1153" name="my_pet[]" value="cat" checked="checked" />cat</label>
<label><input type="checkbox" class="wpuf_my_pet_1153" name="my_pet[]" value="dog" checked="checked" />dog</label>
<label><input type="checkbox" class="wpuf_my_pet_1153" name="my_pet[]" value="hamster" />hamster</label>

Any idea?


1 Answer 1


Use PHP explode function and convert string into array using a delimiter | then you can use foreach loop.


$str = get_the_author_meta('my_pet', $author_id);
$pets_array = explode('| ', $str);

if (is_array($pets_array)) {
    foreach ($pets_array as $pet) {
        echo $pet;
        echo 'somtext';
        echo '<br />';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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