I'm trying to add some custom user meta on the registeration. For example, I have field to set a fruit :

function some_fruits($fruit= false) {
    $fruits= array();
    $fruits['1'] = 'Apple';
    $fruits['2'] = 'Banana';
    $fruits['3'] = 'Apricot';
    if ($fruit) {
        return $fruits[$fruit];
    } else {
        return $fruits;

But when I call this field with

$display_fruit = get_user_meta($user_id, 'fruit', true);

it displays 1 instead of Apple. How can I solve this ?


Fastest way would be something like this:

$fruit_id = get_user_meta($user_id, 'fruit', true); //returns 1
$display_fruit = some_fruits($fruit_id); //will return 'Apple'
  • Do not bash self to head for too long. This happens awfuly a lot in my own code :) – Pavel Janicek Sep 16 '18 at 11:02

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.