Created
February 3, 2012 07:35
-
-
Save Steven-Rose/1728787 to your computer and use it in GitHub Desktop.
WP: Query for current author ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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