0

I'm looking to retrieve a specific meta value for users from the Wordpress types plugin. I know the value is stored in a wpcf-team-experience-member-type. This is a checkbox option and I'd like to retrieve a list of all selected values.

Right off the bat if I do something like:

var_dump(get_user_meta($user->ID, 'wpcf-team-experience-member-type'))

I get something like this:

array(1) { [0]=> array(1) { ["wpcf-fields-checkboxes-option-f4fe375f6cad3c44eff97e6e6f16deb2-1"]=> array(1) { [0]=> string(7) "student" } } }

wpcf seems to put all of its values inside of an array, and on top of that the checkbox values are stored in an array as well. In this case, the value I'm looking for is 'student' but that array might have multiple values.

How would I go about retrieving it? Thank you!

0

The reason you get the "First" Array is that you don't use the "single" option of the get_user_meta function. Try this:

$arr = get_user_meta($user->ID, 'wpcf-team-experience-member-type',true);
$options = array();
if(is_array($arr)){
    foreach($arr as $key => $value){
        foreach($value as $arrvalue){
             $options[] = $arrvalue;
        }
    }
}
var_dump($options);

This should dump all the options that maybe are in there.

Happy Coding, Kuchenundkakao

  • Sorry for the late reply, thank you very much this solved it :) – James Myers Aug 21 '15 at 1:12
0

The array is just contain another array that contains the array where the 'student' is located.

You can use array_keys() to return all the keys or a subset of the keys of the array and access the string 'student' with integer keys instead of an int-string-int [0]["wpcf-fields-checkboxes-option-f4fe375f6cad3c44eff97e6e6f16deb2-1"][0], like this:

$arr = get_user_meta($user->ID, 'wpcf-team-experience-member-type');
$keys = array_keys($arr);
var_dump($keys[0][0][0]);
0

Try var_dump(get_user_meta($user->ID, 'wpcf-team-experience-member-type'), true).

The third parameter for get_user_meta (called $single) specifies whether to return a single value (true) or an array (false). The default is false.

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.