Check if WP_User_Query ‘include’ is empty

I think the problem here is that in the process of violating this rule, you’ve created confusion and problems: do 1 thing per statement, 1 statement per line Coupled with another problem: Passing arrays to the APIs which get stored as serialised PHP ( security issue ) And another: Always check your assumptions it ignores … Read more

pre_user_query meta_query admin user list

You are using pre_user_query according to WordPress documentation Fires after the WP_User_Query has been parsed, and before the query is executed Then you should use pre_get_users just like pre_get_posts when your arguments have some meaning to WordPress. pre_get_users Fires before the WP_User_Query has been parsed Replace your hook with add_action(‘pre_get_users’, ‘modify_user_list’);

How to add custom query filters in WP_User_Query

The pre_user_query action hook in WordPress will allow you alter the SQL statements in the WP_User_Query object before they are run against the database. Note, this is an action, not a filter, so there’s no need to return the $user_query that gets passed in. add_action( ‘pre_user_query’, ‘add_my_custom_queries’ ); function add_my_custom_queries( $user_query ) { $user_query->query_fields .= … Read more

WP_User_Query with combined meta query – not working?

It looks like you’re using wrong parameters, please try this instead (untested): $q = new WP_User_Query( array( ‘role’ => ‘contributor’, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘first_meta’, ‘value’ => ‘2’, ), array( ‘key’ => ‘second_meta’, ‘value’ => ”, ‘compare’ => ‘!=’ ) ) ) ); where we’ve used the key, value and … Read more

Wp_User_Query not sorting by meta key

you can try this code $args = array( ‘meta_query’ => array( array( ‘key’ => ‘score’, ‘value’ => 0, ‘compare’ => ‘>’, ‘type’ => ‘numeric’ ) ), ‘orderby’ => ‘meta_value_num’, ‘number’ => 20 ); $suggested_user_query = new WP_User_Query( $args ); $users = $suggested_user_query->get_results(); echo ‘<div id=”user_suggest”>’; echo ‘<ul>’; foreach ($users as $user) { // get all … Read more

Want to add my custom prepare query but add_filter doesn’t run

The WP_User_Query allows meta_query searches exactly like the other WP_*_Query classes. Example here: global $wpdb; $author_search = new WP_User_Query( array( ‘role’ => ‘subscriber’, ‘fields’ => ‘all_with_meta’, // if it’s a digit/int/float, use ‘meta_value_num’ ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’, // you could try -1 as well. ‘nuber’ => 99999999, ‘meta_query’ => array( ‘key’ => ‘my_userpoints’, … Read more