iain-g
iain-g

Reputation: 193

wordpress - output get_user_meta array as ul

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

Answers (1)

Rajat Sharma
Rajat Sharma

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

Related Questions