How do I sort a WP_USER_QUERY by multiple meta fields?

You can do it with ‘orderby’ parameter. Parameter description: Field(s) to sort the retrieved users by. May be a single value, an array of values, or a multi-dimensional array with fields as keys and orders (‘ASC’ or ‘DESC’) as values. Accepted values are ‘ID’, ‘display_name’ (or ‘name’), ‘include’, ‘user_login’ (or ‘login’), ‘login__in’, ‘user_nicename’ (or ‘nicename’), … Read more

custom post type ‘pre_[cpt]_query’ hook

WP doesn’t provide (as far as I remember) hooks specific to CPTs. There are a lot of hooks in WP_Query class to bend the post queries different ways. In most cases they are passed the query object itself, which is used to derive the context (such as is query for specific post type).

WP_User_Query Filter Results

Mostly a PHP question but if I understand your question, you want something like this: $args = array( ‘role’ => ‘talent’, ‘order’ => ‘DESC’, ‘orderby’ => ‘user_registered’, ‘meta_key’ => ‘position’, ‘number’ => ’15’ ); $meta = array ( array( ‘key’ => ‘picture’, ‘value’ => array(”), ‘compare’ => ‘NOT IN’ ), array( ‘key’ => ‘position’, ‘value’ … Read more

How to put an array in wp user query

This sounds like a job for the wp_parse_id_list() function. It will return an array of unique IDs, sanitized with the absint() function: $csv = bp_get_following_ids(); if( 0 !== $csv ) ) { $uids = wp_parse_id_list( $csv ); $user_query = new WP_User_Query( [ ‘include’ => $uids ] ); } where we assume that bp_get_following_ids() returns a … Read more

Change users.php WP_User_Query

pre_get_users is the action that is fired before a user query is run. You need to check the context of the action to make sure you’re on the main users screen. You can then alter the query with any parameters accepted by WP_User_Query. A quick example: function wpd_filter_users( $query ) { $screen = get_current_screen(); if( … Read more

construct complex queries with WP User Query

$meta_query_args = array( ‘meta_query’ => array( ‘relation’ => ‘OR’, // Optional, defaults to “AND” array( ‘key’ => ‘_my_custom_key’, ‘value’ => ‘Value I am looking for’, ‘compare’ => ‘=’ ), array( ‘relation’ => ‘AND’, array( ‘key’ => ‘_my_custom_key_2’, ‘value’ => ‘Value I am looking for 2’, ‘compare’ => ‘=’ ), array( ‘key’ => ‘_my_custom_key_3’, ‘value’ => … Read more

WP_User_Query and user posts

If you pass in the fields parameter to your user query you can easily get an array of ids to the pass in to your wp query : //WP User Query $author_query = new WP_User_Query( array ( ‘number’ => 3, ‘fields’ => ‘ID’ )); $author_results = $author_query->results; //WP Query $postArgs = array ( ‘author__in’=> $author_results, … Read more