do_action_ref_array( 'pre_user_query', WP_User_Query $this )
Fires after the WP_User_Query has been parsed, and before the query is executed.
Description Description
The passed WP_User_Query object contains SQL parts formed from parsing the given query.
Parameters Parameters
- $this
-
(WP_User_Query) The current WP_User_Query instance, passed by reference.
Source Source
Changelog Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Find user by usermeta add change the meta key or add more meta keys
OR meta_key='key_name'between () on WHERE line<?php add_action( 'pre_user_query', function( $uqi ) { global $wpdb; $search = ''; if ( isset( $uqi->query_vars['search'] ) ) $search = trim( $uqi->query_vars['search'] ); if ( $search ) { $search = trim($search, '*'); $the_search = '%'.$search.'%'; $search_meta = $wpdb->prepare(" ID IN ( SELECT user_id FROM {$wpdb->usermeta} WHERE ( ( meta_key='first_name' OR meta_key='last_name' ) AND {$wpdb->usermeta}.meta_value LIKE '%s' ) )", $the_search); $uqi->query_where = str_replace( 'WHERE 1=1 AND (', "WHERE 1=1 AND (" . $search_meta . " OR ", $uqi->query_where ); } });Expand full source codeCollapse full source code