#34060 closed defect (bug) (fixed)
WP_Query zero offset parameter doesn't override paged
Reported by: | mazurstas | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 4.3.1 |
Component: | Query | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
When offset parameter is set to zero paged parameter is taken into account.
Attachments (2)
Change History (13)
#1
@
9 years ago
- Milestone changed from Awaiting Review to 4.4
- Owner set to boonebgorges
- Status changed from new to assigned
#3
@
9 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
I just found that r34697 breaks code that uses get_posts( array( 'paged' => $x ) )
since offset
will default to 0
it will always override paged
.
This breaks, for instance, the sample code provided at https://vip.wordpress.com/documentation/writing-bin-scripts/#faq
#4
@
9 years ago
A workaround is to explicitly pass a non-numeric offset
, for example:
<?php $posts = get_posts( array( 'paged' => $x, 'offset' => null, ) );
But this is not ideal.
#5
@
9 years ago
@westonruter offset
should not default to 0
. By default, it shouldn't be set. Do you have a filter or something else that's setting offset
to 0
?
#6
@
9 years ago
@boonebgorges I'm using get_posts()
without 'suppress_filters' => false
, and this function has an offset
of 0
among its $defaults
:
<?php function get_posts( $args = null ) { $defaults = array( 'numberposts' => 5, 'offset' => 0, // <========= HERE 'category' => 0, 'orderby' => 'date', 'order' => 'DESC', 'include' => array(), 'exclude' => array(), 'meta_key' => '', 'meta_value' =>'', 'post_type' => 'post', 'suppress_filters' => true ); /* ... */
#7
@
9 years ago
Ah right, get_posts()
. (Damn you, get_posts()
!) Let me think about this - it might be able to change the default values of get_posts()
without breaking backward compatibility.
#8
@
9 years ago
- Keywords has-patch added
@westonruter As I suspected, it looks like we can just pull the offset=0
default out of get_posts()
. The tests in [34060.diff] should demonstrate that the behavior matches pre-[34697] behavior. Can I ask you to verify?
#9
@
9 years ago
- Keywords commit added
Qapla'!
Change in 34060.diff offset=>null
to be omitted and for paged
to be respected.
Hi mazurstas - Welcome to Trac! Good catch here.