[wp-trac] [WordPress Trac] #24142: Zero value for posts_per_page value in wp_query custom instance and for 'Blog pages show at most' option

WordPress Trac noreply at wordpress.org
Tue Mar 3 22:19:56 UTC 2020


#24142: Zero value for posts_per_page value in wp_query custom instance and for
'Blog pages show at most' option
--------------------------------------------+-----------------------------
 Reporter:  alexvorn2                       |       Owner:  (none)
     Type:  defect (bug)                    |      Status:  reopened
 Priority:  normal                          |   Milestone:  Future Release
Component:  Query                           |     Version:
 Severity:  normal                          |  Resolution:
 Keywords:  needs-unit-tests needs-testing  |     Focuses:
--------------------------------------------+-----------------------------
Changes (by Howdy_McGee):

 * keywords:  needs-patch needs-unit-tests => needs-unit-tests needs-testing


Comment:

 I think we can get away with `==` if we convert the given value to integer
 after checking if we need to provide a default. Similar to the `showposts`
 conditional directly below `pre_get_posts`.

 Giving `posts_per_page` a TRUE boolean already translates to 1 (post per
 page) so it would make sense for FALSE to translate to 0 and return 0
 posts.

 This certainly **needs tested** but from what I've run it works as
 expected. To compare to the previously listed chart:

 {{{
 value           posts_per_page  showposts       posts_per_archive_page
 posts_per_rss
 --------------------------------------------------------------------------------------
 null    |       default         default         default
 default
 ''      |       default         default         default
 default
 0       |       0               0               0                       0
 '0'     |       0               0               0                       0
 true    |       1               1               1                       1
 false   |       0               0               0                       0
 10      |       10              10              10                      10
 '10'    |       10              10              10                      10
 'string'|       default         default         default
 default
 array() |       default         default         default
 default
 -1      |       all             all             all
 all
 -2      |       2               2               2                       2
 }}}

 I think in the end it makes `posts_per_page` a bit more predictable for
 edges cases such as this. The biggest change users should be aware of is
 how booleans passed to `posts_per_page` works.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/24142#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list