Hi mightyx3n,
Hoe this will help you more.
/*--------------------------------------------------------------
[usermeta data="first_name,last_name"] = For specific fields
[usermeta data="*"] or [usermeta] = For all fields
-------------------------------------------------------------*/
function my_current_usermeta($atts) {
$default = array(
'data' => '*',
);
$fields = shortcode_atts($default, $atts);
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
$user_meta_data = array();
if($fields['data'] == '*'){
$userdata = get_user_meta($user_id);
foreach($userdata as $user_meta_key => $user_meta_val){
if(is_serialized($user_meta_val[0])){
$user_meta_data[$user_meta_key] = unserialize($user_meta_val[0]);
} else {
$user_meta_data[$user_meta_key] = $user_meta_val[0];
}
}
} else {
$fields = explode(',', $fields['data']);
foreach($fields as $field){
$user_meta_data[$field] = get_user_meta($user_id, $field, true);
}
}
return $user_meta_data;
} else {
return array();
}
}
add_shortcode('usermeta', 'my_current_usermeta');
-
This reply was modified 2 years, 5 months ago by Yui.
-
This reply was modified 2 years, 5 months ago by bcworkz. Reason: code format fixed