Articles of wp user query

Complex WP_User_Query call fails on production server

I’m having a very specific and hard to debug problem with a complex meta_query in a WP_User_Query call: I’m using this (simplified) code to built the query: // custom user role $arguments = array( ‘role’ => ‘member’ ); // number and offset $arguments[‘number’] = 10; $arguments[‘offset’] = 0; $meta = array(); $meta[‘relation’] = ‘AND’; // […]

Pagination not working on custom query

I am trying to change pages when I search by category on my website. When I am not searching under a certain category I can switch pages fine but when I am searching for a category I am unable to switch pages. $paged = ( get_query_var( ‘paged’ ) ) ? absint( get_query_var( ‘paged’ ) ) […]

how to get list of all users and their metadata

How do I get a list of all users with role = ‘Customers’ including all the metadata per user, means wp_users + wp_usermeta. Query below does not generate the wanted results. $query = “SELECT * FROM wp_users INNER JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id ORDER BY ID DESC’); “; $data = $wpdb->get_results($query,ARRAY_A); But that list […]

Basic Wp_user_query not finding any users

For some reason, the most basic wordpress user query i got from this generator https://generatewp.com/wp_user_query/ is displaying that it has not found any users $args = array ( ); // The User Query $user_query = new WP_User_Query( $args ); // The User Loop if ( ! empty( $user_query->results ) ) { foreach ( $user_query->results as […]

pre_user_query meta_query admin user list

I’m attempting to use pre_user_query’ to change the query to include somemeta_query` variables. My goal is to only display users in the user list if they share a common meta_value with the current logged in user… function modify_user_list($query){ $user = wp_get_current_user(); if( ! current_user_can( ‘edit_user’ ) ) return $query; $user_id = $user->ID; $user_branch_number = get_user_meta($user_id, […]

How to add custom query filters in WP_User_Query

I am creating a list of all users in wordpress. For that I am using WP_User_Query with meta_query so that I can show only filtered users. I am stuck where I want to add a custom query filters in SELECT p.distance_unit * DEGREES(ACOS(COS(RADIANS(p.latpoint)) * COS(RADIANS(mt30.meta_value )) * COS(RADIANS(p.longpoint) – RADIANS(mt31.meta_value)) + SIN(RADIANS(p.latpoint)) * SIN(RADIANS(mt30.meta_value)))) AS […]

List Users alphabetically with heading

How can I show a list of Users with alphabetical headings? For example: AAdamAlan BBillBob I’ve found examples that do it with Posts, but I can’t figure out how to make it work with WP_User_query() 🙁

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 […]

How to get a list of all users registered before a given date?

I was expecting to be able to do something like the following which I thought would return all users that have registered before a given date: $args = array( ‘post_type’ => ‘post’, ‘date_query’ => array( array( ‘before’ => current_time( ‘mysql’ ) ) ) ); $query = new WP_User_Query( $args ); However, unlike WP_Query, WP_User_Query doesn’t […]

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 […]