This is my code:
$args = array (
'order' => 'DESC',
'include' => get_user_meta($author->ID, 'the_following_users', true)
);
$wp_user_query = new WP_User_Query( $args );
$users = $wp_user_query->get_results();
if ( ! empty( $users ) ) {
foreach ( $users as $user ) {
// Get users
}
} else {
echo 'Error.';
}
The user meta 'the_users' may be empty so if it's empty it's got to me all registered users if not empty it's print the users that I need.
The problem that if ( ! empty( $users ) ) { }
is not reading if 'include' is empty or not, I know I can make a variable and check first if the variable is empty or not but I don't need this I want to check if 'include' is empty by using '$wp_user_query->get_results()'.
EDIT:
As Nicolai answer we can replace true to false from get_user_meta code and the problem will be solved and if the include is empty the WP-User_Query will return a false and print error.
The problem now that if include not empty so the code must be working without any issues but that does not happen it ignores the users that stored in 'the_users' user meta and print only current user.
Here's the value of 'the_users' user meta:
a:19:{i:0;s:2:"89";i:3;s:3:"105";i:4;s:2:"74";i:5;s:3:"111";i:6;s:3:"167";i:7;s:2:"83";i:8;s:2:"54";i:9;s:2:"87";i:10;s:2:"85";i:11;s:2:"77";i:13;s:2:"82";i:14;s:2:"60";i:15;s:3:"149";i:16;s:3:"160";i:17;s:2:"71";i:18;s:1:"3";i:19;s:1:"2";i:20;s:3:"121";i:21;s:2:"57";}
Here's how i stored 'the_users' user meta data:
$the_following_users = get_user_meta($the_follower, "the_following_users", true);
if(!in_array($user_follow_to, $the_following_users) && is_array($the_following_users)){
$the_following_users[] = $user_follow_to;
} else {
$the_following_users = array($user_follow_to);
}
update_user_meta($the_follower, "the_following_users", $the_following_users);