WP CLI – show users whose ID is larger than given ID

One way to work with existing WP-CLI commands is through the WP_CLI::runcommand(). Here are two examples how we can filter an existing WP-CLI command, namely the wp user list command based on WP_User_Query and it’s pre_user_query hook: Run a custom script in WP-CLI Let’s write our script.php file with: <?php add_action( ‘pre_user_query’, ‘wpse_pre_user_query’ ); WP_CLI::runcommand( … Read more

Searching user meta using WP_User_Query

Try this: $yoursearchquery = ‘This is my search’; $users = new WP_User_Query(array( ‘search’ => $yoursearchquery, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘shoe_size’, ‘value’ => $yoursearchquery, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘shoe_color’, ‘value’ => $search_operation, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘shoe_maker’, ‘value’ => $yoursearchquery, ‘compare’ => ‘=’ ) ) … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)