How do I retrieve meta_key names with get_user_meta($user_id) call
Question
I’d like to retrieve the meta_key names, (and values), for all wp_usermeta records for 1 specific user.
While I can do this by querying the database with the proper SQL I can’t get it with the get_user_meta function call.
Using $wpdb->get_result
$all_user_meta = $wpdb->get_results ( "SELECT * FROM wp_usermeta WHERE user_id = $user_id " );
if ( !empty($all_user_meta) )
{
$cnt = 0 ;
$idx = -1 ;
foreach ( $all_user_meta as $one_meta )
{
$meta_key = $one_meta->meta_key ;
echo('Meta Key: '.$meta_key.'<br/>');
THIS WORKS !!
}
}
Using WordPress function Call
$user_meta_array = get_user_meta($user_id) ;
foreach($user_meta_array as $user_meta)
{
$meta_key = $user_meta->meta_key ;
echo('Meta Key: '.$meta_key.'<br/>');
THIS DOES NOT WORK !!
The loop does execute the proper number of times
}
0
php
4 years
2020-03-23T16:52:58-05:00
2020-03-23T16:52:58-05:00 0 Answers
106 views
0
Leave an answer