Skip to content

Instantly share code, notes, and snippets.

@Steven-Rose
Created February 3, 2012 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Steven-Rose/1728787 to your computer and use it in GitHub Desktop.
Save Steven-Rose/1728787 to your computer and use it in GitHub Desktop.
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