Ticket #1969 (closed defect: fixed)

Opened 3 years ago

Last modified 10 months ago

Check for category and author page existence

Reported by: chuyskywalker Assigned to: anonymous
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

is_category.diff (1.0 kB) - added by chuyskywalker on 11/27/05 10:27:39.
fixes said category/404 bug
is_category-better.diff (0.9 kB) - added by chuyskywalker on 11/27/05 10:28:53.
whoops, added a bit exta to that last one…

Change History

11/27/05 10:27:39 changed by chuyskywalker

  • attachment is_category.diff added.

fixes said category/404 bug

11/27/05 10:28:53 changed by chuyskywalker

  • attachment is_category-better.diff added.

whoops, added a bit exta to that last one...

11/27/05 10:30:49 changed by chuyskywalker

  • cc set to bg|has-patch.

... and then, like lightening, it strikes and I find the culprit.

11/27/05 12:55:35 changed by davidhouse

  • cc deleted.
  • keywords set to bg|has-patch.

Tags go in the Keywords field, not the CC field. :)

11/27/05 17:01:26 changed by chuyskywalker

hehe, what a noob :) Thanks! (That's what I get for submitting patches at 2am...)

11/28/05 03:16:06 changed by matt

  • status changed from new to closed.
  • resolution set to fixed.

(In [3215]) Don't show 404s for empty cats, fixes #1969

02/17/06 01:30:57 changed by joelgilmore

  • 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 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.

07/31/06 13:48:50 changed by _ck_

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.

11/29/06 23:08:25 changed by matt

  • milestone changed from 2.1 to 2.2.

03/27/07 19:59:22 changed by foolswisdom

  • keywords changed from bg|has-patch to has-patch.
  • milestone changed from 2.2 to 2.3.

09/01/07 15:19:54 changed by westi

  • keywords changed from has-patch to needs-patch.

This needs-patch for the remaining issue - "empty author's"

Marking at such.

09/12/07 03:00:34 changed by ryan

  • milestone changed from 2.3 to 2.4 (next).

12/20/07 08:46:13 changed by JDTrower

A patch that fixes tickets #3345 and #1969 has been posted on #3345. It needs testing, however it fixes the problems mentioned in this ticket.

01/24/08 17:44:37 changed by Nazgul

  • status changed from reopened to closed.
  • version changed from 2.0.1 to 2.0.
  • resolution set to fixed.
  • milestone deleted.

Reclosing as fixed, as the remaining issue is being adressed in #3345.