WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#5324 closed defect (bug) (fixed)

404 error on empty category page

Reported by: othellobloke Owned by: 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 6 years ago.
Addresses this issue, if it needs fixing that is
5324-handle404.diff (1.0 KB) - added by technosailor 6 years ago.
5324.diff (892 bytes) - added by ryan 6 years ago.
archive.diff (3.6 KB) - added by caesarsgrunt 6 years ago.
Empty archive fix for default template, first try.
5324.2.diff (1.2 KB) - added by DD32 5 years ago.

Download all attachments as: .zip

Change History (41)

comment:1 Viper007Bond6 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.

comment:2 follow-up: pishmishy6 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?

pishmishy6 years ago

Addresses this issue, if it needs fixing that is

comment:3 pishmishy6 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.

comment:4 in reply to: ↑ 2 Viper007Bond6 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... ;)

comment:5 pishmishy6 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.

comment:6 Viper007Bond6 years ago

  • Keywords needs-patch added; has-patch removed

comment:7 technosailor6 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.

comment:8 technosailor6 years ago

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

technosailor6 years ago

comment:9 technosailor6 years ago

  • Keywords dev-feedback added

comment:10 technosailor6 years ago

  • Milestone changed from 2.9 to 2.7

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

comment:11 ryan6 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.

comment:12 AaronCampbell6 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.

comment:13 AaronCampbell6 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?

comment:14 technosailor6 years ago

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

comment:15 ryan6 years ago

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

comment:16 caesarsgrunt6 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!!!

ryan6 years ago

comment:17 ryan6 years ago

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

comment:18 caesarsgrunt6 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?

comment:19 ryan6 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.

comment:20 AaronCampbell6 years ago

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

comment:21 ryan6 years ago

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

comment:22 follow-up: mrmist6 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.)

comment:23 in reply to: ↑ 22 caesarsgrunt6 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.

comment:24 caesarsgrunt6 years ago

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

comment:25 ryan6 years ago

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

comment:26 caesarsgrunt6 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.

caesarsgrunt6 years ago

Empty archive fix for default template, first try.

comment:27 caesarsgrunt6 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!

comment:29 pishmishy6 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.

comment:30 AaronCampbell6 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.

comment:31 ryan6 years ago

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

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

comment:32 AaronCampbell5 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?

comment:33 DD325 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

comment:34 AaronCampbell5 years ago

My bad, thanks.

comment:35 DD325 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.

DD325 years ago

comment:36 ryan5 years ago

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

Note: See TracTickets for help on using tickets.