#57816 closed defect (bug) (fixed)
WordPress shows author archive in sitemap even if there are no posts
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.4 | Priority: | normal |
Severity: | normal | Version: | 5.5 |
Component: | Sitemaps | Keywords: | good-first-bug has-patch has-unit-tests commit |
Focuses: | Cc: |
Description
It looks like this should be avoided: If there are no posts in the WP installation (only pages), the wp-sitemap.xml
still contains the author archive. And if you follow the link, you get a 404 error.
This couldn't make sense for SEO ...
Change History (16)
#2
@
2 years ago
Found this:
Should only be generated for those authors with at least 1 published post.
Source: https://github.com/GoogleChromeLabs/wp-sitemaps/issues/23
Looks like this is a bug then.
#4
follow-up:
↓ 5
@
22 months ago
The WP_User_Query
in WP_Sitemaps_Users
uses 'has_published_posts'
to only list users with at least 1 published post in any post type (including pages, excluding attachments).
Since pages are not normally shown in the author archives, we could add unset( $public_post_types['page'] );
here:
That said, the author archive for a user with no published posts returns a 200 status (albeit an empty page), not a 404. So... not sure if that needs to be changed at all 🤷♂️
Edit: also, what happens if a site actually does show pages in author archives too?
#5
in reply to:
↑ 4
@
21 months ago
- Keywords 2nd-opinion added
Replying to swissspidy:
That said, the author archive for a user with no published posts returns a 200 status (albeit an empty page), not a 404. So... not sure if that needs to be changed at all 🤷♂️
Yes, that's true. But still not very helpful to report an empty page to Google, or not?
Edit: also, what happens if a site actually does show pages in author archives too?
I'm not sure if an edge case like this should stop us fixing this for the 99% others.
But I'm just looking at my installations and the missing UI to disable the sitemap with no real content.
If you think this is technically correct and needs no fixing, then we can close it. From a UX point of view, I'm still finding this very confusing.
#6
@
21 months ago
- Keywords good-first-bug needs-unit-tests added; 2nd-opinion removed
- Milestone changed from Future Release to 6.4
Let's just do it.
- Adding
unset( $public_post_types['page'] );
- Adding a test to verify the new behavior
This ticket was mentioned in PR #4846 on WordPress/wordpress-develop by nirav7707.
21 months ago
#7
- Keywords has-patch added; needs-patch removed
Trac Ticket -> https://core.trac.wordpress.org/ticket/57816
This PR addresses the issue of including users in the user sitemap who have not published any posts but have published pages.
To resolve this, we have implemented a modification. By using the unset( $public_post_typespage? ); function, we remove the public post type "page" from the query arguments. This ensures that users who have only published pages are not included in the user sitemap.
This ticket was mentioned in PR #4900 on WordPress/wordpress-develop by @swissspidy.
20 months ago
#8
- Keywords has-unit-tests added; needs-unit-tests removed
Trac ticket: https://core.trac.wordpress.org/ticket/57816
@swissspidy commented on PR #4846:
20 months ago
#9
Thanks for your contribution!
As this change needs an accompanying unit test, I have just opened another PR to add one: #4900
I'm closing yours in favor of the new one. But don't worry, you should still get props for your contribution! 🙂
#10
@
20 months ago
- Owner set to swissspidy
- Status changed from new to reviewing
Props @niravsherasiya7707 for the PR. I just added some unit tests. This should be good to go now.
@swissspidy commented on PR #4900:
20 months ago
#11
@pbiron Would love to get your review on this one
#13
@
18 months ago
Test Report
I Test 4900.diff ✅ working
Environment
OS: macOS m1
WordPress 6.4-alpha-56267-src
PHP 7.4.33
nginx/1.25.2
MySQL 5.7.43
Browser: Chrome 116.0.5845.140
Theme: Twenty Twenty v2.3
Active Plugins: No plugins activated.
Expected Results
✅ Don't show the author's sitemap if there are no posts
Actual Results
✅ After Applying Patch. working properly
Yes whenever page is added, author archive is present in the sitemap.xml
Is this a bug, I don't know
About 404 error, I think it depends on a theme (that was not an issue in my local wordpress-develop installation)
If this is a bug, I'm willing to provide a patch (just not sure about that)
For now, I'm leaving the code to possibly fix this as a use of a filter