• Resolved mabufoysal

    (@mabufoysal)


    I have custom post type Task where I assigned Users as Volunteers.

    https://i.stack.imgur.com/Yqnum.png

    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.

Viewing 1 replies (of 1 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @mabufoysal

    Relationships are done by ID, not the values so you can only search (filter) on the user ID.
    You might be able to go use custom SQL with joins to fix it but this will get quite complex and is out of range for Pods support.

    Cheers, Jory

Viewing 1 replies (of 1 total)
  • The topic ‘Count post type of Pods entity’ is closed to new replies.