Query users by capability – uninstall/deactivate callback

It was actually much easier than I originally thought – just doing a WP_User_Query for a meta value (meta arrays are supported as well, like for the other query classes). public function on_deactivate() { $meta_key = ‘tools_page_tsi_per_page’; $query = new WP_User_Query( array( ‘meta_key’ => $meta_key ) ); if ( empty( $query->results ) ) return; foreach … Read more

Basic Wp_user_query not finding any users

the most basic wordpress user query […] is displaying that it has not found any users You’re passing an empty array of query arguments and there’s an explicit check for that in the WP_User_Query constructor: /** * PHP5 constructor. * * @since 3.1.0 * * @param null|string|array $query Optional. The query variables. */ public function … Read more

WordPress User getting added with id of 0

The ID column if the wp_users table is the Primary Key and auto-incremented. If your table isn’t set that way then something must’ve gone wrong while it was getting created. Try deleting all the tables from the database and re-installing WordPress.

How to query users who have empty first_name?

It looks like you’re searching for the first_name meta keys with empty string meta values: $options = array( ‘meta_query’ => array( array( ‘key’ => ‘first_name’, ‘value’ => ”, ‘compare’ => ‘=’, ), ) ); $users = get_users( $options ); that generates this kind of SQL query: SELECT wp_users.* FROM wp_users INNER JOIN wp_usermeta ON ( … Read more

How to customize user search

I was able to find a solution: if(!empty($search)){ $query = $wpdb->prepare( “SELECT DISTINCT user_id FROM wp_usermeta WHERE meta_key = ‘pie_address_3’ AND meta_value LIKE %s “, ‘%’ . $search . ‘%’ ); $ids = $wpdb->get_results($query); ?> <ul class=”author-list”> <?php foreach ($ids as $id) { ?> <li> <img width=”90″ height=”90″ src=”https://wordpress.stackexchange.com/questions/182955/<?php echo get_user_meta($id->user_id,”pie_profile_pic_5″, true); ?>” class=”attachment-agent-image wp-post-image”> … Read more