Tag Info

Hot answers tagged

7

This should get you really close. I haven't tested it, but it's nearly identical to a setup I've used a few times. /* * We start by doing a query to retrieve all users * We need a total user count so that we can calculate how many pages there are */ $count_args = array( 'role' => 'Subscriber', 'fields' => 'all_with_meta', ...


5

The search parameter can take an email address and can also accept wildcards: $wp_user_search = new WP_User_Query( array( 'search' => '*@mydomain.com' ) ); $users = $wp_user_search->get_results();


4

Well I have come up with 2 solutions. Solution 1 - foreach loop and verify each user This one is based off of @GhostToast's solution, but with updated WordPress functions //new query with default args $author_query = new WP_User_Query(); // Get the results $authors = $author_query->get_results(); if( $authors ) { foreach( $authors as $author ) ...


4

Searching the main table Simply use WP_User_Query with a search argument. So if you want to search for example for a user with a keyword in his user_email or similar columns from the {$wpdb->prefix}users table, then you can do the following: $users = new WP_User_Query( array( 'search' => '*'.esc_attr( $your_search_string ).'*', ...


3

@m0r7if3r provided the correct answer. For the sake of providing a directly usable snippet to anyone else looking at this issue, here's what I ended up using. $wp_users = $wpdb->get_results(" SELECT users.*, meta.meta_value FROM $wpdb->users AS users LEFT JOIN $wpdb->usermeta AS meta ON users.ID = meta.user_id WHERE ...


3

Made something myself: Page template file: <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $paged -= 1; $limit = 20; $offset = $paged * $limit; $args = array( 'number' => $limit, 'offset' => $offset, ); // Create the WP_User_Query object global $wp_query; $wp_query = new WP_User_Query($args); // Get the results ...


3

I don't see an "orderby Rand()" parameter for either get_users or WP_User_Query. There is a filter called pre_user_query that could be used but I am not sure I see the benefit of that when shuffle will randomize the array you already have. $args = array( 'fields' => 'all_with_meta', 'exclude' => array(1), ); $users = get_users( $args ); ...


2

No, it isn't possible without modifications to the p2p plugin, as indicated here: https://github.com/scribu/wp-posts-to-posts/issues/374 Relevant code is here: https://github.com/scribu/wp-posts-to-posts/blob/master/core/connection-type.php#L374


2

Filter the string 'query' and change the ORDER BY part. See https://gist.github.com/1281778#L160 for an example.


2

WP_User objects have some magic methods which do allow you to access any custom field: foreach ( $agents as $agent ) { var_dump( $agent->bio ); var_dump( $agent->get( 'bio' ) ); } The two are equivalent. More info: http://scribu.net/wordpress/the-magic-of-wp_user.html


2

This is covered in the link you reference: The search_columns attribute does not set what should be searched for in each column, but instead specifies which columns should be searched for the term set in 'search'. Specifically, you can only search for one term - but you can look in one or more columns. //Search user logins & emails for 'foo'. ...


1

You can use the WP_User_Query class which works much like WP_Query. The docs: http://codex.wordpress.org/Class_Reference/WP_User_Query Below is a dump of the WP_User object that it will return, in this example using: $wp_user_search = new WP_User_Query( array( 'fields' => 'all_with_meta' ) ); $get_users = $wp_user_search->get_results(); This ...


1

As Brian noted, your form sends the data via POST, and you are fetching via GET. Change for method to "GET" or else use the $_POST variable. (But note that your search term is passed along using your current code, because both POST and GET populate the $_REQUEST variable). You can make the search more flexible by ensuring that it is surrounded by wildcard ...


1

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 ) ) ...


1

How to use the class methods in the callback The $query object inside pre_user_query is a fully qualified core object, so you can use $query->set( 'key', 'value' ); as well as $query->get( 'key' );. If you got the problem that this might interfere with other callbacks, then simply add remove_filter( current_filter(), __FUNCTION__ ); to your callback, ...


1

This worked for me. $user_query = new WP_User_Query( array( 'search' => '*example.net*', 'search_columns' => array('user_url') )); $authors = $user_query->get_results(); The wild card to be used in the search string is '*' and not '%'. Also you have to include the 'search_columns' parameter with the following possible values search_columns = ...


1

Mashable Follow is custom built for Mashable.com, so you won't find a plugin that brings that level of integration to your WordPress site. That said, there are two that may suit your purpose: Social: Integrates your WordPress site with social networking sites Twitter and Facebook, thereby offering a whole lot of features including—automatically ...


1

Thank you for your attantion, I made it working with update_user_meta Here is my little function I wrote global $blog_id; $current_blog_details = get_blog_details( array( 'blog_id' => $blog_id ) ); if (is_user_logged_in()) { $user = wp_get_current_user(); $last_visited_blogs = get_user_meta($user->ID, 'last_visited_blogs',true); ...


1

I found the following class in the add user autocomplete plugin . It extends the normal searcha and allows '*'; Example: $wp_user_search = new A2B_User_Query( array( 'search' => $s . '*' ) ) ; class A2B_User_Query extends WP_User_Query { /** * @see WP_User_Query::get_search_sql() */ function get_search_sql( $string, $cols, $wild = false ) ...


1

I ran your code, and the problem I see seems to be opposite what you describe-- Page 1 never sets as the current page. Assuming that is the issue, I understand the puzzlement. That one is tricky to work out. You need to set base to an absolute URL. 'base' => get_permalink( get_the_ID() ). '%_%', Or something similar that works in the context your need. ...


1

After a lot of trial and error I learnt that WP_User_Query takes an argument fields which can be set to 'all_with_meta'. This reduces number of queries to two for any number of users that are fetched in a single go and also provides benefits of caching. Usage would look like: $user_query = new WP_User_Query( array('include' => $post_authors, 'fields' ...


1

As I know or at the moment of the last time I checked, ACF doesn't meta-data in their "best" location, as in get_term_meta, or meta data for users. Instead of that, Elliot did a very strange thing, but focusing in what you're asking for: get_field('your-field','user_' . $author->ID); So the loop you will have to add something like above, check out ...


1

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', ...


1

You can set the type of the data in your meta_query. Unfortunately, you can only use the comparison BETWEEN if your date is in the format YYYYMMDD. So to see the users for one year, you would have to set your metaquery like this: $usersByCompanyArgs = new WP_User_Query( array( 'fields' => 'all_with_meta', 'orderby' => ...



Only top voted, non community-wiki answers of a minimum length are eligible