Support

Account

Home Forums General Issues Filter User Query Reply To: Filter User Query

  • Hi, still totally lost on this.

    I have updated the query to look like this:

    <?php
    $args = array(
    'meta_query' => array(
            'relation' => 'AND',
    			array(	
    			'meta_key' => 'department',
    			'meta_value' => 'Social Work',
    			'meta_compare' => '=',
    			),
    			
    			array(
    			'meta_key' => 'last_name',
    			'orderby' => 'meta_value',
    			'order' => 'ASC',
    			'exclude' => array(1,8,9),
    			),	
      )
    );
    
    // The Query
    $user_query = new WP_User_Query( $args );
    
    // User Loop
    if ( ! empty( $user_query->results ) ) {
    	foreach ( $user_query->results as $user ) {
    		um_fetch_user( $user->id );	
    ?>

    So the way I read this is that it should be looking for users that have “SOCIAL WORK” checked off in the “DEPARTMENT” ACF field that I created….(its a checkbox field).

    AND, it should then look at the USER LAST NAME, and ORDER those in ASC order.

    However when I do this code, I still get tons of users listed linked to all kinds of departments, not just ones that include SOCIAL WORK as I want.

    Please help!