Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WP: Query for current author ID
* Query DB for current author ID
* @global class $wpdb Global WordPress Database class
* @param String $author Author name from URL, identical to user_nicename in users table
* @return String User ID of author
function get_author_id( $author ) {
global $wpdb;
$author_id = $wpdb->get_results( "SELECT `ID` from $wpdb->users u WHERE u.`user_nicename` = '$author'" );
return $author_id[0]->ID;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment