Wrong result in fetching User meta of WordPress
I have custom post type Task
where I assigned Users as Volunteers.
Now I would like to fetch how many tasks assigned to a Volunteer.
I am using below code.
$users = new WP_User_Query(array(
'meta_query' = array(
'relation' = 'OR',
array(
'key' = 'last_name',
'value' = $_POST['search'],
'compare' = 'LIKE',
),
),
));
$users_found = $users-get_results();
$names = array();
foreach ($users_found as $user) {
$this_users_tasks = get_user_meta($user-ID,'task',false);
$names[$user-ID] = $user-display_name.' ('.count($this_users_tasks).')';
}
echo json_encode($names);
die;
But I am getting wrong result.
Topic wp-user-query user-meta Wordpress
Category Web