I need to display on some specific pages some selected user meta data (not all), for some users.
On the Wordpress Codex page for the get_user_meta()
function we have this example (user_id = 9):
<?php
$all_meta_for_user = get_user_meta( 9 );
print_r( $all_meta_for_user );
?>
The results of this example:
Array ( [first_name] => Array ( [0] => Tom ) [last_name] => Array ( [0] => Auger) [nickname] => Array ( [0] => tomauger ) [description] => etc.... )
And a Note (shortened):
... you may want to run a simple array_map() on the results of get_user_meta() in order to take only the first index of each result (this emulating what the $single argument does when $key is provided:
if( $all_meta_for_user = get_user_meta( $user_id ) )
$all_meta_for_user = array_map( function( $a ){ return $a[0]; }, get_user_meta( $user_id ) );
print_r( $all_meta_for_user );
The result:
Array ( [first_name] => Tom [last_name] => Auger [nickname] => tomauger [description] => etc.... )
My question is:
How to put this in a function that will display, for example, the user last and first names with a shortcode (but really I need more user meta data)?
What I mean? On a specific page we put a shortcode with the user ID and the related function must return the meta data for each selected key of this user. Is this possible? Can anyone help me?