Make WordPress Core

Opened 14 years ago

Closed 13 years ago

Last modified 12 years ago

#15770 closed defect (bug) (fixed)

WP_Query queries for non-existant pages result in is_404() = false & is_page() = true

Reported by: dd32's profile dd32 Owned by: ryan's profile ryan
Milestone: 3.4 Priority: normal
Severity: normal Version: 2.9
Component: Query Keywords: has-patch
Focuses: Cc:

Description

WP_Query queries for non-existant pages result in is_404() = false & is_page() = true

For example:

$query = array('pagename' => 'this-is-a-404-page');

$query = new WP_Query($query);

var_dump($query);


?>
object(WP_Query)[223]
  public 'query_vars' => 
    array
      'pagename' => string 'this-is-a-404-page' (length=18)
      'error' => string '' (length=0)
      'name' => string 'this-is-a-404-page' (length=18)
      'static' => string '' (length=0)
      'page_id' => int 0
      'post_type' => string '' (length=0)
  <Sniped extra empty query vars for paste length>

  public 'tax_query' => 
    object(WP_Tax_Query)[111]
      public 'queries' => 
        array
          empty
      public 'relation' => string 'AND' (length=3)
  public 'post_count' => int 0
  public 'current_post' => int -1
  public 'in_the_loop' => boolean false
  public 'comment_count' => int 0
  public 'current_comment' => int -1
  public 'found_posts' => int 0
  public 'max_num_pages' => int 0
  public 'max_num_comment_pages' => int 0
  public 'is_single' => boolean false
  public 'is_preview' => boolean false
  public 'is_page' => boolean true
  public 'is_archive' => boolean false
  public 'is_date' => boolean false
  public 'is_year' => boolean false
  public 'is_month' => boolean false
  public 'is_day' => boolean false
  public 'is_time' => boolean false
  public 'is_author' => boolean false
  public 'is_category' => boolean false
  public 'is_tag' => boolean false
  public 'is_tax' => boolean false
  public 'is_search' => boolean false
  public 'is_feed' => boolean false
  public 'is_comment_feed' => boolean false
  public 'is_trackback' => boolean false
  public 'is_home' => boolean false
  public 'is_404' => boolean false
  public 'is_comments_popup' => boolean false
  public 'is_paged' => boolean false
  public 'is_admin' => boolean true
  public 'is_attachment' => boolean false
  public 'is_singular' => boolean true
  public 'is_robots' => boolean false
  public 'is_posts_page' => boolean false
  public 'is_post_type_archive' => boolean false
  public 'query' => 
    array
      'pagename' => string 'this-is-a-404-page' (length=18)
  public 'request' => string ' SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND (wp_posts.ID = '0') AND wp_posts.post_type = 'page'  ORDER BY wp_posts.post_date DESC ' (length=137)
  public 'posts' => 
    array
      empty

This is not a regression, Tested in 3.0 and 2.9. To me it doesnt make sense for a instance of WP_Query to not reset the conditionals after a unsuccessful request.

This does not affect front end, as the WP Class is responsible for determining that WP_Query has returned nill results and 404'ing.

Attachments (2)

15770.diff (756 bytes) - added by benbalter 13 years ago.
First (rough) pass at returning 404 on non-existent pages
15770.2.diff (1.5 KB) - added by nacin 13 years ago.

Download all attachments as: .zip

Change History (10)

#1 @dd32
14 years ago

See #15771 which was caused as a result of this.

#2 @nacin
14 years ago

  • Milestone changed from Awaiting Review to Future Release

@benbalter
13 years ago

First (rough) pass at returning 404 on non-existent pages

#3 @benbalter
13 years ago

  • Cc Ben@… added
  • Keywords has-patch dev-feedback needs-testing added

@nacin
13 years ago

#4 @nacin
13 years ago

I mentioned to benbalter how the logic in 15770.diff could be improved a bit. Then I tried to actually improve it myself, and got fed up with the current statements in handle_404(), and ended up with 15770.2.diff.

#5 @benbalter
13 years ago

  • Keywords dev-feedback needs-testing removed

Tested, and nacin's 15770.2.diff fixes the problem.

#6 @ryan
13 years ago

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

In [19892]:

404 non-existant pages. Make handle_404() readable. Props benbalter, nacin. fixes #15770

#7 @SergeyBiryukov
13 years ago

  • Milestone changed from Future Release to 3.4

#8 @scribu
12 years ago

This ticket seems to talk about ?pagename, but the actual patch seems to have more to do with ?page.

In any case, I foresee a lot of complaints from query_posts() fans. :)

Note: See TracTickets for help on using tickets.