Support

Account

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

  • Hi @juiceex

    You need to put the ‘meta_key’, ‘orderby’, ‘order’, and ‘exclude’ options outside of the ‘meta_query’ option like this:

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

    Please check the example on the bottom of the page I gave you before.

    Hope this helps 🙂