Opened 7 years ago

Closed 5 years ago

#1969 closed defect (bug) (fixed)

Check for category and author page existence

Reported by: chuyskywalker Owned by: 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 (2)

is_category.diff (1.0 KB) - added by chuyskywalker 7 years ago.
fixes said category/404 bug
is_category-better.diff (877 bytes) - added by chuyskywalker 7 years ago.
whoops, added a bit exta to that last one…

Download all attachments as: .zip

Change History (14)

fixes said category/404 bug

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

  • Cc bg|has-patch added

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

  • Cc bg|has-patch removed
  • Keywords bg|has-patch added

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

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

comment:4   matt7 years ago

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

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

  • Milestone changed from 2.0 to 2.1
  • Resolution fixed deleted
  • 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
  • Version changed from 1.6 to 2.0.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.

comment:6   _ck_7 years ago

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:7   matt6 years ago

  • Milestone changed from 2.1 to 2.2
  • 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.

  • Milestone changed from 2.3 to 2.4 (next)

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.

  • Milestone 2.5 deleted
  • Resolution set to fixed
  • Status changed from reopened to closed
  • Version changed from 2.0.1 to 2.0

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

Note: See TracTickets for help on using tickets.