Make WordPress Core

Opened 16 years ago

Closed 15 years ago

Last modified 15 years ago

#5324 closed defect (bug) (fixed)

404 error on empty category page

Reported by: othellobloke's profile othellobloke Owned by: technosailor's profile technosailor
Milestone: 2.7 Priority: normal
Severity: normal Version: 2.5
Component: General Keywords: has-patch dev-feedback
Focuses: Cc:

Description

spoken to many people who believe this isn't good functionality and probably a bug. i'm not a coder so I might be wrong, but i hope not.

wordpress returns a 404 error when a category page is viewed that's empty.

Attachments (5)

5324-classes.php.patch (851 bytes) - added by pishmishy 16 years ago.
Addresses this issue, if it needs fixing that is
5324-handle404.diff (1.0 KB) - added by technosailor 16 years ago.
5324.diff (892 bytes) - added by ryan 16 years ago.
archive.diff (3.6 KB) - added by caesarsgrunt 16 years ago.
Empty archive fix for default template, first try.
5324.2.diff (1.2 KB) - added by DD32 15 years ago.

Download all attachments as: .zip

Change History (41)

#1 @Viper007Bond
16 years ago

  • Keywords needs-patch added
  • Milestone changed from 2.5 to 2.4
  • Version set to 2.4

Confirmed on trunk. Displays the error 404 page and sends a 404 header for the archive view of an empty but existing category.

It should display as normal and when the template check for have_posts() or whatever fails, the "no matching posts" error will be shown.

#2 follow-up: @pishmishy
16 years ago

Question...

Does this occur only when you manually construct the URL itself, or is WordPress automatically generating a link to the page for the empty category which results in a 404?

@pishmishy
16 years ago

Addresses this issue, if it needs fixing that is

#3 @pishmishy
16 years ago

  • Keywords has-patch added; needs-patch removed
  • Owner changed from anonymous to pishmishy
  • Status changed from new to assigned

Sorry, ignore that file. It's not complete.

#4 in reply to: ↑ 2 @Viper007Bond
16 years ago

Replying to pishmishy:

Question...

Does this occur only when you manually construct the URL itself, or is WordPress automatically generating a link to the page for the empty category which results in a 404?

Well, it's the same URL, so... ;)

#5 @pishmishy
16 years ago

  • Owner changed from pishmishy to anonymous
  • Status changed from assigned to new

Actually I think this one is beyond me to fix cleanly.

#6 @Viper007Bond
16 years ago

  • Keywords needs-patch added; has-patch removed

#7 @technosailor
16 years ago

Patch attached. Fixes WP::handle_404() to ensure that emoty archives are not treated as 404 and instead serves a 200 allowing the Loop to take over.

#8 @technosailor
16 years ago

  • Keywords has-patch added; needs-patch removed
  • Owner changed from anonymous to technosailor
  • Status changed from new to assigned

#9 @technosailor
16 years ago

  • Keywords dev-feedback added

#10 @technosailor
16 years ago

  • Milestone changed from 2.9 to 2.7

hopefully, one of the devs can look at this and maybe get it in.

#11 @ryan
16 years ago

My only concern is that some templates assume that there are posts when there is not a 404. I think that's probably a small number of templates, however. The patch seems worth a shot for 2.7.

#12 @AaronCampbell
16 years ago

On my first few test, the latest patch seems to be working perfectly. I'd REALLY like to see this in 2.7.

#13 @AaronCampbell
16 years ago

I applied the patch by technosailor to my 2.6.1 install and it's working great. I'd still like to see this submitted to trunk. What do we still need to do to make that happen?

#14 @technosailor
16 years ago

Yeah, let's get it in and beat on it so I know if it needs any further changes.

#15 @ryan
16 years ago

For taxonomy and author queries, shouldn't we be checking to see if the queried object is empty and 404 if so.

#16 @caesarsgrunt
16 years ago

I've always been frustrated by this bug. The page should exist, and say there are no articles by that author (etc). It shouldn't return a 404!

Get it into trunk!!!

@ryan
16 years ago

#17 @ryan
16 years ago

Here's a version that makes sure the various archive queries matched an object. If not, 404.

#18 @caesarsgrunt
16 years ago

Um... What's an object? If I visit the page http://www.example.com/author/fred/, but author Fred hasn't yet written anything, does your patch stop the 404 from being returned? If so, what is returned?

#19 @ryan
16 years ago

If the user Fred doesn't exist, we should 404. If he does exist but has not written anything, we should not 404.

#20 @AaronCampbell
16 years ago

Ryan: That's working better. It 404 for things like invalid categories, but not for empty categories.

#21 @ryan
16 years ago

(In [8761]) Don't 404 for categories, tags, and authors that exist but have no posts. see #5324

#22 follow-up: @mrmist
16 years ago

It still doesn't look quite right to me - Now instead of a 404 you get "Not found", which doesn't really seem any better from the viewer's perspective. "Not found" does not really explain the situation - does it mean "author not found" or "no posts found", etc..

If the author exists (with posts), you get a page heading of "Author Archive" (with posts below.). It seems that if the author exists (without posts) it should still say "Author Archive" and simply not list any posts, rather than saying "Not found".

(This may be a templating issue which distincts it from the coding issue, I suppose, in which case it needs a change to the behaviour of the default template.)

#23 in reply to: ↑ 22 @caesarsgrunt
16 years ago

Replying to mrmist:

Yes, I absolutely agree. Basically the only change so far is the error code, which whilst it is an improvement hardly affects the visitor. The solution isn't very user-friendly solution yet.
Yes, it may be a templating issue. I can't remember. But if it is then, as you say, it should be changed in the default template.

+1 for "Author Archive" heading with no posts. Perhaps a message below saying "there are no posts by this author", or similar.

#24 @caesarsgrunt
16 years ago

See also #3345. There are some patches for this issue there, though I haven't looked at them...

#25 @ryan
16 years ago

It is a templating issue. The language in archive.php can be changed.

#26 @caesarsgrunt
16 years ago

OK; I'll make a patch for the default template.

I don't think a 404 should be returned for date archives with no posts either, this should be fixed in the same way.

@caesarsgrunt
16 years ago

Empty archive fix for default template, first try.

#27 @caesarsgrunt
16 years ago

Oh sorry, I've jut realised that diff contains some other fixes as well (tidying up the page title)...
I'll clean it up later or tomorrow and try again, but have a look at the relevant part anyway!

#29 @pishmishy
15 years ago

If you have a comment to make regarding a fix for this issue, or your need for a fix, please make it, but please don't 'bump' tickets. The lack of action is not because we aren't aware of the ticket's existence.

#30 @AaronCampbell
15 years ago

That's fair. I should have asked my question rather than bumping the topic. Where do we stand on this? I've been using the patch successfully for quite a while now, on a few different sites. I think we're just waiting on the default theme to be updated to handle this? If this is the case I'll update that and upload a patch.

#31 @ryan
15 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [9226]) Better not found messages. Props caesarsgrunt. fixes #5324

#32 @AaronCampbell
15 years ago

Am I mistaken, or did we add the changes to archive.php but not make technosailor's changes to classes.php that made it necessary?

#33 @DD32
15 years ago

Am I mistaken, or did we add the changes to archive.php but not make technosailor's changes to classes.php that made it necessary?

There was this comment furthur up that touched classes.php, not sure if its the one you're after though..

08/28/08 19:58:57 changed by ryan

(In [8761]) Don't 404 for categories, tags, and authors that exist but have no posts. see #5324

#34 @AaronCampbell
15 years ago

My bad, thanks.

#35 @DD32
15 years ago

get_userdatabylogin(get_query_var('author_name'))->display_name

I dont think thats PHP4 compatible, as you cant use the return value of a function as a object reference, on the back of [wp-testers] Tag error in default theme i'll attach a patch for that.

@DD32
15 years ago

#36 @ryan
15 years ago

(In [9577]) Eliminate chaining for php 4 compat. Props DD32. fixes #5324

Note: See TracTickets for help on using tickets.