Reputation: 193
I'm having trouble getting meta data from an array in a template.php - I have the following code:
<?php
$user_id = get_current_user_id();
$key = 'service_checkboxes';
$single = false;
$user_last = get_user_meta( $user_id, $key, $single );
echo $user_last;
?>
This outputs: Array
I've also tried:
<?php
$user_id = get_current_user_id();
$key = 'service_checkboxes';
$single = false;
$user_last = get_user_meta( $user_id, $key, $single );
print_r($user_last);
?>
This outputs: Array ( [0] => Array ( [0] => pet_cat [1] => pet_dog [2] => pet_rabbit ) )
What I'd like is
(These are the original labels on the checkboxes in the user profile)
Any help greatly appreciated!
Upvotes: 0
Views: 308
Reputation: 161
Here is the final answer
$user_id = get_current_user_id();
$key = 'service_checkboxes';
$single = true;
$user_last = get_user_meta( $user_id, $key, $single );
echo '<ul>';
foreach ($user_last as $val){
$formated_val = ucwords(str_replace('pet_','',$val));
echo '<li>'.$formated_val.'</li>';
}
echo '</ul>';
Upvotes: 1