WordPress.org

Make WordPress Core

Opened 17 months ago

Last modified 16 months ago

#37202 new defect (bug)

the_archive_title() doesn't output the author's display name if that author hasn't posted

Reported by: henry.wright Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.5.3
Component: Users Keywords: has-patch
Focuses: template Cc:

Description

In my archive.php template, if I do this:

get_header();
the_archive_title( '<h1>', '</h1>' );
// Rest of code...

and then take a look at example.com/author/joebloggs, I expect to see:

Author: Joe Bloggs

The problem is if joebloggs hasn't posted yet, I see this:

Author:

Attachments (1)

37202.diff (748 bytes) - added by henry.wright 16 months ago.

Download all attachments as: .zip

Change History (5)

#1 @henry.wright
17 months ago

I've traced the issue back to the use of the $authordata global, which is used inside get_the_author().

Dumping $authordata in the author template and then visiting a user's archive I get either an object of type WP_User (for users who have posted) or null (for users who haven't posted).

Last edited 17 months ago by henry.wright (previous) (diff)

#2 @SergeyBiryukov
16 months ago

  • Component changed from General to Users
  • Focuses template added

#3 @SergeyBiryukov
16 months ago

  • Keywords needs-patch added

@henry.wright
16 months ago

#4 @henry.wright
16 months ago

  • Keywords has-patch added; needs-patch removed

37202.diff uses get_the_queried_object() to output the author's display name on author archives. Now, the_archive_title() will output a title even if the author hasn't posted.

Note: See TracTickets for help on using tickets.