get_author_posts_url() WordPress Function
If you're a Wordpress developer, then you're probably familiar with the get_author_posts_url() function. This function is used to get the author's posts URL. The function takes one parameter, the author's ID, and returns the author's posts URL. So, if you want to get the URL of the author's posts, you would use the get_author_posts_url() function like this: $author_id = 1; $author_posts_url = get_author_posts_url( $author_id ); echo $author_posts_url; The output of the above code would be: http://example.com/author/1 As you can see, the get_author_posts_url() function is a very handy function for Wordpress developers.
get_author_posts_url( int $author_id, string $author_nicename = '' ) #
Retrieves the URL to the author page for the user with the ID provided.
Parameters
- $author_id
(int)(Required)Author ID.
- $author_nicename
(string)(Optional) The author's nicename (slug).
Default value: ''
Return
(string) The URL to the author's page.
Source
File: wp-includes/author-template.php
function get_author_posts_url( $author_id, $author_nicename = '' ) { global $wp_rewrite; $author_id = (int) $author_id; $link = $wp_rewrite->get_author_permastruct(); if ( empty( $link ) ) { $file = home_url( '/' ); $link = $file . '?author=' . $author_id; } else { if ( '' === $author_nicename ) { $user = get_userdata( $author_id ); if ( ! empty( $user->user_nicename ) ) { $author_nicename = $user->user_nicename; } } $link = str_replace( '%author%', $author_nicename, $link ); $link = home_url( user_trailingslashit( $link ) ); } /** * Filters the URL to the author's page. * * @since 2.1.0 * * @param string $link The URL to the author's page. * @param int $author_id The author's ID. * @param string $author_nicename The author's nice name. */ $link = apply_filters( 'author_link', $link, $author_id, $author_nicename ); return $link; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
2.1.0 | Introduced. |