get_author_posts_url

Retrieve the URL to the author page for the user with the ID provided.

Description

(string) get_author_posts_url( (int) $author_id, (string) $author_nicename = '' ); 

Returns (string)

The URL to the author's page.

Parameters (2)

0. $author_id (int)
The author id.
1. $author_nicename — Optional. (string) => ''
The author's nicename (slug). Default empty.

Usage

  1. if ( !function_exists( 'get_author_posts_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/author-template.php'; 
  3.  
  4. // The author id. 
  5. $author_id = -1; 
  6.  
  7. // Optional. The author's nicename (slug). Default empty. 
  8. $author_nicename = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_author_posts_url($author_id, $author_nicename); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/author-template.php  
  1. function get_author_posts_url( $author_id, $author_nicename = '' ) { 
  2. global $wp_rewrite; 
  3. $auth_ID = (int) $author_id; 
  4. $link = $wp_rewrite->get_author_permastruct(); 
  5.  
  6. if ( empty($link) ) { 
  7. $file = home_url( '/' ); 
  8. $link = $file . '?author=' . $auth_ID; 
  9. } else { 
  10. if ( '' == $author_nicename ) { 
  11. $user = get_userdata($author_id); 
  12. if ( !empty($user->user_nicename) ) 
  13. $author_nicename = $user->user_nicename; 
  14. $link = str_replace('%author%', $author_nicename, $link); 
  15. $link = home_url( user_trailingslashit( $link ) ); 
  16.  
  17. /** 
  18. * Filters the URL to the author's page. 
  19. * @since 2.1.0 
  20. * @param string $link The URL to the author's page. 
  21. * @param int $author_id The author's id. 
  22. * @param string $author_nicename The author's nice name. 
  23. */ 
  24. $link = apply_filters( 'author_link', $link, $author_id, $author_nicename ); 
  25.  
  26. return $link;