Support » Fixing WordPress » is_404() is true and have_posts() is also true?!

  • Resolved AndreyPutilov

    (@andreyputilov)


    Hello, I have developed my own theme with index.php file but without 404.php

    The problem is present when URL is like mysite.com/meaninglesstext, but everything is good, when URL is mysite.com/category/invalidpostname

    I am testing is_404() and have_posts() at the very beginning of index.php file, no code is included before, but both conditions turn out true;

    I have no self-made post types, I have turned off all plugins. Permalink settings are /%category%/%postname%/ . I tryed to change category and tag prefixes placing casual text, but no effect, though it is not important. Thanks in advance

Viewing 7 replies - 1 through 7 (of 7 total)
  • esmi

    (@esmi)

    Forum Moderator

    is_404() won’t work as it tests for a 404 page. If you just use
    if ( have_posts() ):

    then you can add your 404 text as part of an else: after the main Loop.

    Ok, I have created a 404.php file, and it solved my problem, but I am still interested, why have_posts returns true.

    Why the first case mysite.com/meaninglesstext produces a query, but another case mysite.com/category/invalidpostname does not.

    esmi

    (@esmi)

    Forum Moderator

    I am still interested, why have_posts returns true.

    Does it? Do you have an else: code block?

    shurely it does, it outputs a list of all new posts. It is not equal to the previous query

    esmi

    (@esmi)

    Forum Moderator

    If posts are being output after the Loop, then you have serious problems in that template file.

    No, it is not my problem. Look, I have created a clean index.php file with this code

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    The result is http://www.peeep.us/7b74626d

    Ok, this is a very strange behaviour but I am not looking forward to dealing with it cause a creation of 404.php file is an acceptable solution.

    In any case I want to thank esmi and all the rest because it helped me to sort out what is running in a wrong way and what is not.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘is_404() is true and have_posts() is also true?!’ is closed to new replies.