[wp-trac] [WordPress Trac] #7472: query_posts() kills is_404 flag

WordPress Trac wp-trac at lists.automattic.com
Wed Aug 6 15:58:29 GMT 2008


#7472: query_posts() kills is_404 flag
---------------------+------------------------------------------------------
 Reporter:  donncha  |       Owner:  anonymous
     Type:  defect   |      Status:  new      
 Priority:  normal   |   Milestone:  2.6.1    
Component:  General  |     Version:  2.6      
 Severity:  normal   |    Keywords:           
---------------------+------------------------------------------------------
 Repeated usage of query_posts() destroys the 404 status flag for a page.

 This probably hasn't been noticed before because the 404.php theme file
 will have been selected by the time query_posts() is used (say in a
 theme).

 How to reproduce:

 Add this code to your sidebar: (or any other query_posts() call that
 generates posts)
 `query_posts("cat=23&posts_per_page=12");`


 In the footer of your theme's index.php (or 404.php if it's there) add
 this code:
 `<?php if( is_404() ) { echo "<p>" . $_SERVER[ 'REQUEST_URI' ] . " is a
 404</p>"; } ?>`

 Add and remove the query_posts() call. The "is a 404" message will
 disappear and reappear. query_posts() creates a new global WP_Query and
 all status flags get overwritten.

 I discovered this bug while trying to figure out why wp-super-cache was
 caching 404 pages. Eventually I used the template_redirect action to
 remember the 404 status for use later on. People have complained about wp-
 super-cache caching 404 pages for quite some time so this is probably a
 long standing bug.

-- 
Ticket URL: <http://trac.wordpress.org/ticket/7472>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list