1

I am trying to get the authors user_id on a page linked to by using get_author_posts_url(),.

For example

http://example.com/author/John%20Smith 

where John Smith is user_id is 23. I need to get 23.

0

On an "author" page get_query_var('author') will give you the ID.

get_queried_object() will get you considerably more author information.

$author = get_queried_object();
echo $author->ID;
// var_dump($author); // to see all of the information available.

For retrieving custom author data follow the Codex.

  • I am getting a bool(false) – MonOve Aug 5 '13 at 18:32
  • For which one? I tested both and they do work but this will only work on a proper "author" page which seems to be the case based on the URL you posted. – s_ha_dum Aug 5 '13 at 18:38
  • My apologies, it works. How can I access this within a plugin? – MonOve Aug 5 '13 at 18:42
  • Saying "in a plugin" changes the context a lot. You will have to do more explaining, possibly start another question. – s_ha_dum Aug 5 '13 at 19:15
0

First extract the nice name of the author from the author url, then you can get the author then you need to query the wp_users table like bellow.

$nicename =  "gowrisankar"; // example
global $wpdb;

$wpdb->get_var( $wpdb->prepare( "SELECT ID FROM wp_users WHERE user_nicename = %s ",$nicename));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.