Ticket #1969 (closed defect (bug): fixed)
Check for category and author page existence
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | General | Version: | 2.0 |
| Severity: | normal | Keywords: | needs-patch |
| Cc: |
Description
If you create a category, and then try to access it before there are any posts in it, Wordpress will return you the 404.php page instead of the category.php.
I would have assumed that you'd get a category.php with no posts on it -- the category *does* exist, it's just empty.
Attachments
Change History
chuyskywalker — 6 years ago
-
attachment
is_category.diff
added
chuyskywalker — 6 years ago
-
attachment
is_category-better.diff
added
whoops, added a bit exta to that last one...
comment:1
chuyskywalker — 6 years ago
- Cc bg|has-patch added
... and then, like lightening, it strikes and I find the culprit.
comment:2
davidhouse — 6 years ago
- Cc bg|has-patch removed
- Keywords bg|has-patch added
Tags go in the Keywords field, not the CC field. :)
comment:3
chuyskywalker — 6 years ago
hehe, what a noob :) Thanks! (That's what I get for submitting patches at 2am...)
- Status changed from new to closed
- Resolution set to fixed
comment:5
joelgilmore — 6 years ago
- Status changed from closed to reopened
- Summary changed from Empty categories return 404 instead of using archive.php to Check for category and author page existence
- Resolution fixed deleted
- Version changed from 1.6 to 2.0.1
- Milestone changed from 2.0 to 2.1
I think a better modification, which I can't see that this does, is to check whether the category (or author page) exists, and if so, go to it even if it has no posts.
The appropriate code would be
if (is_author() || is_category()){
if ((!$wp_query->get_queried_object()) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER['QUERY_STRING']) && (false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) {
$wp_query->set_404();
status_header( 404 );
} elseif( is_404() != true ) {
status_header( 200 );
}
} else { // If not in an author or category page
if ( (0 == count($wp_query->posts)) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER['QUERY_STRING']) && (false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) {
$wp_query->set_404();
status_header( 404 );
} elseif( is_404() != true ) {
status_header( 200 );
}
}// End author/cat select
This works very well on my <a href=" http://www.dividingline.org/>site</a>, and also applies to author pages, since I display information about Subscribers as well as Contributors et al.
What is really strange is that for a user/author with no posts:
/index.php?author_name=example works and will show author.php template even with zero posts
/author/example will FAIL (even in 2.1a2) and show 404 template until they have at least one post and then it will work
I believe it has to do with the way WP_QUERY in query.php parses the URL and first believes it's on a page with posts for the rewrite URL so it fails for the author. Very strange.
The 404 patch code by joelgilmore works but I dislike the idea of patching the result. I wish they could fix it on the parsing. 2.1a2 still does not have any attempt to fix what-so-ever.
comment:8
foolswisdom — 5 years ago
- Keywords has-patch added; bg|has-patch removed
- Milestone changed from 2.2 to 2.3
- Keywords needs-patch added; has-patch removed
This needs-patch for the remaining issue - "empty author's"
Marking at such.
comment:11
JDTrower — 4 years ago
comment:12
Nazgul — 4 years ago
- Status changed from reopened to closed
- Version changed from 2.0.1 to 2.0
- Resolution set to fixed
- Milestone 2.5 deleted
Reclosing as fixed, as the remaining issue is being adressed in #3345.

fixes said category/404 bug