How to query users who have empty first_name?

So far I have tried these three options and all 3 of them are not working. Option 1 $options = array( ‘meta_key’ => ‘first_name’, ‘meta_value’ => ”, ‘meta_compare’ => ‘=’, ); $users = get_users( $options ); Option 2 $options = array( ‘meta_key’ => ‘first_name’, ‘meta_value’ => null, ‘meta_compare’ => ‘=’, ); $users = get_users( $options … Read more

How to customize user search

I’m developing a custom user search and I’m using this plugin found here: <?php function sul_user_listing($atts, $content = null) { global $post; extract(shortcode_atts(array( “role” => ‘technician’, “number” => ’10’ ), $atts)); $role = sanitize_text_field($role); $number = sanitize_text_field($number); // We’re outputting a lot of HTML, and the easiest way // to do it is with output … Read more

WP_User_Query search with multiple search queries

Is it possible to perform a WP_User_Query with multiple search queries? Something like: $args = array ( ‘search’ => ‘*example.com OR *abc.com’, ‘search_columns’ => array( ‘user_email’ ) ); or $args = array ( ‘search’ => array( ‘relation’ => ‘OR’, array( ‘search_columns’ => ‘user_email’, ‘search’ => ‘*example.com’, ), array( ‘search_columns’ => ‘user_email’, ‘search’ => ‘*abc.com’, ) … Read more

Query Users by login, meta & role

I’m using pre_user_query to limit the results shown on the users.php page. I am limiting it by role & also by a meta field, so my query from like this: $query->query_from = ” FROM wp_users INNER JOIN wp_usermeta ON (wp_users.ID = wp_usermeta.user_id) INNER JOIN wp_usermeta AS mt1 ON (wp_users.ID = mt1.user_id) “; And my where … Read more

how to create a proper query for getting a list of users with taxonomy related meta key

I want to list user based on the sub category (which is a taxonmy). It displays users from all the sub category rather than the one I select the sub category from the back end. The code is below, please advise what I am doing wrong: options.php <?php if (!defined(‘FW’)) die(‘Forbidden’); $options = array( ‘heading’ … Read more

Echo the number of users using WP_User_Query?

Ok, so right now I can easily echo the number of posts that has a specific meta_key and meta_value: $query = new WP_Query( array( ‘meta_key’ => ‘usp-custom-1’, ‘meta_value’ => get_permalink() ) ); echo $query->found_posts; I’m trying to do something similar except for echoing the number of users that has a specific user_meta data. I’m trying … Read more

How to use search_columns in WP_User_Query?

I am using WP_User_Query to search use by name, ID, email etc… In that case I need to use search_columns field to pass ID or email of user. What i am doing is $my_users = new WP_User_Query( array( ‘role’ => $role, ‘offset’ => $offset , ‘number’ => $number, ‘fields’ => ‘all’, ‘search_columns’=> array( ‘5’,”, ‘[email protected]’,”,”), … Read more

WP_User_Query order by meta_key that is an array

I have set a user metadata named achievements which is an array containing various numeric values. Using WP_User_Query, I want to order the list by a specific key within this array named points. The following: $args = array( ‘order’ => ‘DESC’, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘achievements’, ‘number’ => $no, ‘offset’ => $offset ); …works … Read more