Get author id from url

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

For example

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

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

Related posts

2 comments

  1. 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.

  2. 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));
    

Comments are closed.