Articles of get users

Order users by last word of last name

This is probably a typical Dutch issue where you have a last name which can contain multiple words. For example Robin van Persie or Mark de Jong. Currently I have a list of users ordered by last name, which is the default for get_users. This works fine most of the time but fails when a […]

Get current user data from external PHP page

I have a PHP page at the same level as the template/theme on WordPress. I need to be able to get the current logged in user details from this page. I have tried this: require_once( $_SERVER[‘DOCUMENT_ROOT’] . ‘/wp-load.php’ ); global $current_user; $current_user = wp_get_current_user(); var_dump( $current_user ); But it’s returning nothing. 0 as user_id and […]

How to list users that have written custom post types and hide the ones that have not?

I’m trying to build an author list that would show all authors that have written a Custom Post Type post, and hide authors that have no posts. With wp_list_authors it would be easy to show users that have written Posts (not CPT). This does not show the users that have published Custom Post Types, it […]

How to use “offset” to paginate get_users?

Is is possible to paginate the get_users function with the “offset” parameter? I have complete my custom query of users for my list and now I need to paginate the results into multiple pages. Here is my sample code: <ul> <?php $args = array( ‘meta_key’ => ‘jabber’, ‘meta_value’ => ‘User Name’, ‘meta_compare’ => ‘LIKE’, ‘order’ […]

get_users meta_query

I can’t get meta_queries working correctly on get_users(). For the life of me can’t figure out what I’m doing wrong. $args = array( ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘minbeds’, ‘value’ => $rooms, ‘compare’ => “<=”, ‘type’ => ‘numeric’ ), array( ‘key’ => ‘maxbeds’, ‘value’ => $rooms, ‘compare’ => “=>”, ‘type’ => […]

Displaying a random user with a shortcode

I’m trying to setup a shortcode to show a single random user each time the page is refreshed. I’ve been successful in displaying all users or a select user by the user ID. Here is my shortcode as it is now: //* Shortcode for getting users function list_of_users( $atts ) { extract( shortcode_atts( array( ‘display’ […]

Select Multiple meta_value from WP DB; Single Query

I am trying to retrieve each user’s first and last name, phone, email, and address from the usermeta table. I’m having trouble selecting multiple meta_values, each with its own meta_key, using a single sql query. I would like the data returned as First Name, Last Name, Phone, Address, Email First Name, Last Name, Phone, Address, […]

Getting all the users who have author privilege

Can anyone tell me how to get all the users who have author privileges by querying the DB in WordPress and order them by number of posts written by them. I use the following query to get all the users from DB: $authors = $wpdb->get_results( “SELECT ID, user_nicename from $wpdb->users ORDER BY display_name” );

get current user not working

I was trying this code to get current user info, but showing nothing. My WordPress version is 3.3.1 <?php wp_get_current_user(); /** * @example Safe usage: $current_user = wp_get_current_user(); * if ( !($current_user instanceof WP_User) ) * return; */ echo ‘Username: ‘ . $current_user->user_login . ‘<br />’; echo ‘User email: ‘ . $current_user->user_email . ‘<br />’; […]

Order get_users() by last login date. Is it possible?

I want to create a page that displays all the blog users ordered by the last login date. I’ve tried with the get_users() function and I can succesfully get the users’ list, but not in the order I want: $query = get_users(‘&offset=’.$offset.’&orderby=login&order=DESC&number=’.$number); I think that the orderby=login is not what I’m looking for… Is there […]