[wp-trac] [WordPress Trac] #11067: Using query_posts() on any subcategories the attached posts_per_page attribute gets lost

WordPress Trac wp-trac at lists.automattic.com
Tue Nov 3 09:59:27 UTC 2009


#11067: Using query_posts() on any subcategories the attached posts_per_page
attribute gets lost
--------------------------+-------------------------------------------------
 Reporter:  voetzi        |        Owner:         
     Type:  defect (bug)  |       Status:  closed 
 Priority:  normal        |    Milestone:         
Component:  General       |      Version:  2.8.5  
 Severity:  normal        |   Resolution:  wontfix
 Keywords:                |  
--------------------------+-------------------------------------------------
Changes (by dd32):

  * status:  new => closed
  * resolution:  => wontfix


Comment:

 This would be occuring as WordPress queries posts & paginates &
 subsequently 404's if there are not posts are available.

 After all that happens, If there are posts available, THEN it reads your
 template, and then repeats everything again thanks to query_posts.

 Solution? Don't use query_posts(), Instead, add a hook and set the
 'posts_per_archive_page' query var, The advantage of this, is that it
 acually works, and you dont query the Database multiple times for every
 archive load (Which is what search engines will be hitting).

 Code to "fix" it for you: (In your themes functions.php file)
 {{{
 add_filter('request', '_request_1_per_archive');
 function _request_1_per_archive($vars) {
         $vars['posts_per_archive_page'] = 1;
         return $vars;
 }
 }}}

 Theres no need for if(is_archive()) or anything, WP_Query will only use
 that var if its actually a archive page. For the code where its used, see
 line 1608 of wp-includes/query.php

 Note: This doesn't affect feeds.

 Closing as wonfix, due to this not being something that can be supported
 within templates.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/11067#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list