Ticket #1969 (closed defect (bug): fixed)

Opened 6 years ago

Last modified 4 years ago

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

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

Change History

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

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

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

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

comment:6   _ck_6 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   matt5 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.

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

Note: See TracTickets for help on using tickets.