Function to pull data from user meta not working

The problem is that when you pass the $key argument on get_user_meta() function, you don’t pass a valid argument. The $key must be a string according to the documentation page. It represents the value of meta_key in the wp_usermeta table.

If with wpcf-client-lvl is actually a variable that contains the name of the field ( lets say $wpcf-client-lvl="client_level" ) replace 'wpcf-client-lvl' with $wpcf-client-lvl. My guess was that this was the actual meta_key name.

I also change some of the syntax code if you don’t mind 🙂

So I believe you copy / paste the following code it will work :

function get_client_lvl(){

    $global $current_user;
    get_currentuserinfo();

    $user_id = $current_user->ID;

    if ($user_id == 0)
        return 'high';

    else {

        $client_lvl= get_user_meta($user_id, 'wpcf-client-lvl', true); 

        if (empty($client_lvl))
            return 'high';

        else
            return $client_lvl;

    }

}

$client_lvl = get_client_lvl();

echo $client_lvl;

UPDATE

In order for the get_current_user_id() to return the ID you must either include pluggable.php ( which I don’t think is a good approach ) or use global variables to get id. I changed the code using the global $current_user.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)