Unless you want to retrieve custom data from the database, you will hardly ever need to make use of the WPDB
class (or its global object, respectively). Though it is obviously possible to do things that way as well.
Just for the sake of completeness, if you had a reason to not use a more abstract function, you’d have to employ JOIN
in the select syntax as user roles live in the usermeta table.
But it’d be much simpler to make use of the get_users
function:
$args = array(
'role' => 'author',
'orderby' => 'display_name'
);
$authors = get_users( $args );
[EDIT] As for the question in the comments (ordering by the number of posts):
Use 'post_count'
as an argument for the 'orderby'
parameter (and read the linked codex page, which gives you all the possible arguments).
Related Posts:
- In what part of the WordPress core does the users table and usermeta table get joined?
- Modify Database in Multi-Site wp_usermeta table
- Best practice to import user base (subscribers) from one website to another?
- How to delete a particular row in a database table
- Select From wpdb – Author/User Directory page
- How to get specific table by current user login
- Using wpdb to connect to a separate database
- WPDB Insert or if exists Update
- Multiple developers / editors working on a site in progress
- get_results using wpdb
- $wpdb won’t insert NULL into table column
- How many users can WordPress handle?
- Get error messages when $wpdb->insert() returns false?
- Detecting errors generated by $wpdb->get_results()
- Does dbDelta delete columns as well?
- wpdb update add current timestamp not working
- How to fetch Data in WordPress using MySQLi or $wpdb
- wpdb->insert multiple record at once
- WordPress Unit Testing – Cannot Create Tables
- How to define composite keys with dbDelta()
- Does wpdb add considerable overhead on queries with large result sets?
- How to track user progress?
- Why does $wpdb return strings for mysql integer values?
- $wpdb->prepare() warning in WordPress 3.5
- Inserting data into custom tables
- Hook into $wpdb
- Display data from a non wordpress database on a page template
- How does $wpdb handle COUNT(*)
- Performance tips for a large user base [closed]
- How might I retrieve a featured post image from an external WP site and display it as a link back?
- WordPress database error: [Query was empty] [closed]
- Export wordpress table to excel
- How to close wpdb connection? [duplicate]
- Inserting Post Meta From SQL
- Why does dbDelta() not catch MysqlErrors?
- Connecting to external oracle database
- Efficiency on displaying random authors based on large database
- Can’t save ajax value to database
- What causes the “max_user_connections” warning on WordPress frontend?
- $wpdb variable throw this error Call to a member function get_results() on a non-object in
- Extend the wp_users table
- Updating all rows of table with $wpdb
- Safe way to find last inserted id in a table?
- How to execute mulitple statement SQL queries using $wpdb->query?
- Is $wpdb->prepare escaping to much? How to use it properly?
- Database slowdown after update to 3.4.1
- How to use user table of a different database for WordPress users?
- When and why should I use $wpdb different return types?
- Subscribers to posts
- How wordpress accesses its own database
- Remove database entries where post_date > expiration date
- Error connecting to DB in /wp-includes/wp-db.php on line 1538 [closed]
- Set Display Name to first and last name (phpmyadmin SQL Query)
- How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?
- Get data from database using $WPDB
- Select Multiple meta_value from WP DB; Single Query
- How to use a different database to list and manage comments in the backend
- Multiple postmeta with same name for one post in wp_postmeta table
- WP Database Table to CSV file
- Cannot update custom database table row
- wpdb_prepare with multiple or condition
- Does WordPress always create unique passwords?
- Show last modified date of database
- $wpdb->insert is not working
- Extracting the post_id via the wp_insert_post action (external db query)
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- Why is it that not all users have a ‘session_tokens’ meta_key record in the usermeta table?
- Change WordPress prefix for only one table?
- Multiple wp_options tables to share content across installs
- Advanced SELECT query with condtional statements
- $wpdb doesn’t like to store arrays
- Select two sums with single get_var statement
- WordPress choose wrong database
- wp_get_current_user always returns 0 continued
- Redirecting to old domain after migration website
- Is there a smart way to obtain a list of only some selected user meta data?
- How can i customize the export personal data file?
- What Is the Proper Way to Merge Usermeta Table to a an existing WP Database?
- Import users from old WP site to new one
- Create table from array with prepare
- How to Access wp_usermeta Data Immediately After a New User is Created
- Update from 4.5 to 4.6 failing
- Does WordPress $wpdb functions wait when table is locked?
- Logins from WP users table use on another page
- How Can I Put Meta_Compare in the Database-Query?
- MS Access to manage WordPress Database
- WordPress running SQL query to update database from form
- 2 WordPress sites with 2 databases but sharing the same users
- $wpdb->insert Giving duplicates
- Convert user passwords to MD5?
- I’m not able to get access to $wpdb [duplicate]
- WPDB SQL query with prepare() returning variable, not db value
- $wpdb error (Call to a member function insert() on a non-object)
- Have working sql query… trying to adjust it to use $wpdb
- Is it important to have integers inserted using %d rather than %s?
- Does WordPress store the username as a primary key in the database?
- Is there a way to execute a php script outside WordPress?
- multiple wordpress installation with shared usertable on an different database
- Problem in using wpdb
- $wpdb->query can’t insert data