0

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 ?

1
  • And how do you set that meta field? Commented Sep 16, 2018 at 10:55

1 Answer 1

2

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'
1
  • Do not bash self to head for too long. This happens awfuly a lot in my own code :) Commented Sep 16, 2018 at 11:02

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.