Opened 10 years ago
Closed 9 years ago
#29644 closed defect (bug) (worksforme)
query_posts doesn't support -1 value for posts_per_page if argument is an array
Reported by: | stratboy | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.0 |
Component: | Query | Keywords: | has-patch needs-testing reporter-feedback |
Focuses: | Cc: |
Description
Using a syntax like this:
$args = array_merge($wp_query->query_vars, array( 'posts_per_page' => -1, 'orderby' => array('menu_order' => 'ASC', 'date' => 'DESC') )); query_posts($args);
I don't get any record. I found it's for the -1 value. If I use any positive integer it returns the right posts in the right order.
Attachments (1)
Change History (8)
#1
follow-up:
↓ 3
@
10 years ago
- Component changed from General to Query
- Keywords reporter-feedback added
#2
@
10 years ago
- Summary changed from query_posts doesn't suppot -1 value for posts_per_page if argument is an array to query_posts doesn't support -1 value for posts_per_page if argument is an array
#3
in reply to:
↑ 1
@
10 years ago
- Summary changed from query_posts doesn't support -1 value for posts_per_page if argument is an array to query_posts doesn't suppot -1 value for posts_per_page if argument is an array
Replying to collinsinternet:
Hi stratboy,
I'm unable to reproduce this issue. Are there more arguments in your query_vars that you are using?
Mmm, no, that's exactly the query I was using. It was used on a taxonomy template page (meaning taxonomy-tax_name.php). I ended up setting a value of 999. It worked just fine.
Note that using string $args instead, -1 is correctly interpreted. Note also that I also tested the array $args with only the 'posts_per_page' query, without the orderby (which features the new v4 syntax) and it didn't work, so I guess the problem is exactly the -1 value when passed as an array.
By the way, the taxonomy is a custom one for a custom post type. Also, I don't get any php error (yes debug mode is active and working).
#4
@
10 years ago
- Summary changed from query_posts doesn't suppot -1 value for posts_per_page if argument is an array to query_posts doesn't support -1 value for posts_per_page if argument is an array
#5
@
10 years ago
- Keywords has-patch needs-testing added; reporter-feedback removed
stratboy, thank you for the information. By creating a custom post type, custom taxonomy and a taxonomy template I was able to duplicate the issue.
It appears that the
$wp_query->query_vars['nopaging']
variable is the cause. If this variable is empty, the SQL LIMIT gets set to whatever the value of posts_per_page is. If it is -1, the LIMIT gets set to -1 and results in a SQL error.
Hi stratboy,
I'm unable to reproduce this issue. Are there more arguments in your query_vars that you are using?