I wondering of how can i override the $curauth to some function to get the current author data, I searched a lot and tested more and more functions without any success.
I used this line into author.php for sure to get the author by slug or name, So how can i get the same author data with another php function?
<?php
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
?>
to be more clear..As we know when we need to get some of user meta we get it like so.
$following = get_user_meta($curauth->ID, '_pwuf_following', true);
Now if i have an function and i need to get the same user meta, What should i do.
NOTE: I need to get the user meta to be public for all users not only for current user!
eg:
function pwuf_following_users () {
$curauth = (...?...);
$following = get_user_meta($curauth->ID, '_pwuf_following', true);
if ( empty($following)) {
//do something
} else {
//Another awesome something
}
}
you need to get all users data using below code:
$users_list = get_users( [ 'role__in' => [ 'author', 'subscriber' ] ] );
foreach ( $users_list as $user ) {
$userdata = get_user_meta($user->ID);
if($userdata != "")
{
//Do something
print_r($userdata); // Here you will get data of specific user by its Id
}
else
{
//Another awesome something
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.