Home WordPress Author Functions get_author_posts_url() WordPress get_author_posts_url() Function Definition In WordPress, get_author_posts_url() returns the web address (URL) of an author archive page. That page lists all posts written by one author.
It returns the URL. It does not print it. Use echo with esc_url() to show the link. Pass the author ID. Inside The Loop you can get it with get_the_author_meta( 'ID' ).
Syntax Pass the author ID. You can also pass the author nicename (the URL-friendly name).
get_author_posts_url( $author_id );
get_author_posts_url( $author_id, $author_nicename ); Call What it does get_author_posts_url( $id )Builds the archive URL for the author with this ID. get_author_posts_url( $id, $slug )Same, but you give the nicename so WordPress does not have to look it up.
This function is not an echo tag. Print the result with echo esc_url( ... ).
Full declaration get_author_posts_url( int $author_id, string $author_nicename = '' ): string Parameters Parameter Description $author_idRequired. The user ID of the author. $author_nicenameOptional. The author's URL-friendly name (user_nicename). Leave it out and WordPress finds it for you.
Return Value Return Value Description string The URL of the author archive, for example https://example.com/author/mari-selvan/.
WordPress Examples Three short theme examples. Each one has a sample output.
1. Basic link 2. Link with author name 3. Fixed author ID Example 1 — Basic link Get the archive URL for the current post author and use it in a link.
<?php
$author_id = get_the_author_meta( 'ID' );
$url = get_author_posts_url( $author_id );
?>
<a href="<?php echo esc_url( $url ); ?>">More posts by this author</a> <a href="https://example.com/author/mari-selvan/">More posts by this author</a> How It Works get_the_author_meta( 'ID' ) returns the ID of the current post author.get_author_posts_url() returns the archive URL for that ID.esc_url() makes the URL safe to print.Example 2 — Link with the author name Show a link such as "All posts by Mari Selvan".
<?php
printf(
'<a href="%s">All posts by %s</a>',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_html( get_the_author() )
);
?> <a href="https://example.com/author/mari-selvan/">All posts by Mari Selvan</a> How It Works printf() puts the URL and the name into the link text.get_the_author() returns the display name.Each value is escaped before it is printed. Example 3 — Fixed author ID and nicename Link to one known author, even outside The Loop.
<?php
$url = get_author_posts_url( 1, 'mari-selvan' );
echo esc_url( $url );
?> https://example.com/author/mari-selvan/ How It Works The first value is the user ID. The second value is the nicename, so WordPress skips the lookup. This works in a footer or sidebar because it does not need The Loop. Frequently Asked Questions What does get_author_posts_url() do in WordPress? It returns the URL of an author archive page. That page lists all posts by one author.
Does get_author_posts_url() print the URL? No. It only returns the URL. Use echo esc_url( get_author_posts_url( $id ) ) to print it.
How do I get the author ID inside The Loop? Use get_the_author_meta( 'ID' ). It returns the ID of the current post author.
Is the nicename parameter required? No. If you leave it out, WordPress finds the nicename from the author ID.
What is the difference between get_author_posts_url() and get_the_author_link()? get_author_posts_url() gives an archive URL on your own site. get_the_author_link() gives a link to the website the author added in their profile.
Which function prints a ready-made author archive link? Use the_author_posts_link(). It prints a full link with the author name as the text.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful
Helpful Share Copy link Suggestion