0

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:

cat
some text for cat

dog
some text for dog

hamster
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?

0

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

Example:-

$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 />';
    }
}
|improve this answer|||||

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.