Support » Fixing WordPress » Repost re 404 error on empty category

  • Hi all, Really sorry to repost.
    Have upgraded to 1.5.1 from 1.5 about 2 days ago. So far` so good except.
    With empty categories (ie no posts in them yet) – if accessed I get a 404 error. It may be something Ive done wrong – or is it the upgrade?
    As soon as I put a post in the empty cat – it all works fine with no error.
    Any clues?? – thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • If there is no post in that category what else do you expect than 404, which means Not found?
    I assume you chose to have displayed even the “empty” categories, because by default WP should not display a category name in menu if there are no posts in it.

    Correct in I chose to display empty cats.
    However on my 1.5 install if there was no post it displayed a search bar rather than a 404 if the cat was empty.
    I understand that if no post is available then it cant find anything but in that case – 404? I mean – sorry to be uppity – but a system as good as WP (and I think it is even if im only 4 WP days old) should be able to swich to a more friendly warning (on an empty cat) – and Im sure it does – so whats happened between 1.5 and 1.5.1 🙂 Okayes ? – thats what Im asking.

    I am not sure it’s a WP problem. I’d check first whether in the theme you are using is the searchform there in the archive.php template?

    Moshu – bang on – see there had to be an answer- its partly my lack of WP smarts where to look. The default theme has a searchform.php include , now I know where to look. In the meantime I have edited the 404 to something less offensive. 🙂 and will study the include to see if I can use that idea. Thanks that was useful – something new.

    Returning 404 when a category is empty is unacceptable in SEO practice. I encountered this problem in WordPress 2.0.2.

    By default, WordPress hides empty categories but there is an option to show them:


    If I decide to show empty categories, WordPress should not be displaying 404 Not Found when users go to click on them.

    Google and other search engines won’t index 404 pages, and if they were previously indexed they get dropped. Very bad!

    Instead what we want is for WordPress to decide, “Is the category Not Found or is it really just empty?”

    In the default WordPress theme by Michael Heilemann, the template file archive.php is prepared to work this way:

    if (have_posts()) :

    // begin the Loop to show posts

    else :

    // explain that there are no posts here


    … but it never gets the chance. *sigh* So here is how you fix the problem.

    inside /wp-includes/classes.php on line 1698:

    if ( (0 == count($wp_query->posts)) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER[‘QUERY_STRING’]) && (false === strpos($_SERVER[‘REQUEST_URI’], ‘?’))) ) ) {


    if ( (0 == $wp_query->query_vars[‘cat’]) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER[‘QUERY_STRING’]) && (false === strpos($_SERVER[‘REQUEST_URI’], ‘?’))) ) ) {

    Then modify your archives.php inside the /theme directory so it is like Heilemann’s example above, but instead of:

    <h2 class=”center”>Not Found</h2>
    <?php include (TEMPLATEPATH . ‘/searchform.php’); ?>

    i recommend:

    No posts here yet.

    or even:

    <h2>Stay tuned!</h2>
    This is a new category. Watch for new posts to appear here soon.

    NOTE: This is assuming you provide the search box in your sidebar like most people do; if that assumption is wrong, make sure you provide the include for searchform.php!

    And that fixes that.

    Whoops. There is a problem with that version above. I meant to say …

    inside /wp-includes/classes.php on line 1698:

    if ( (0 == count($wp_query->posts)) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER[‘QUERY_STRING’]) && (false === strpos($_SERVER[‘REQUEST_URI’], ‘?’))) ) ) {


    if ( (0 == count($wp_query->posts)) && (!isset($wp_query->query_vars[‘cat’]) || $wp_query->query_vars[‘cat’] == 0) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER[‘QUERY_STRING’]) && (false === strpos($_SERVER[‘REQUEST_URI’], ‘?’))) ) ) {

    @mikesmullin – Might consider applying your proposed changes at

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Repost re 404 error on empty category’ is closed to new replies.