WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 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)

29644.patch (514 bytes) - added by collinsinternet 6 years ago.

Download all attachments as: .zip

Change History (8)

#1 follow-up: @collinsinternet
6 years ago

  • Component changed from General to Query
  • Keywords reporter-feedback added

Hi stratboy,

I'm unable to reproduce this issue. Are there more arguments in your query_vars that you are using?

Last edited 6 years ago by collinsinternet (previous) (diff)

#2 @SergeyBiryukov
6 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 @stratboy
6 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).

Last edited 6 years ago by stratboy (previous) (diff)

#4 @SergeyBiryukov
6 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 @collinsinternet
6 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.

Last edited 6 years ago by dd32 (previous) (diff)

#6 @boonebgorges
6 years ago

  • Keywords reporter-feedback added

Can we get some more detailed instructions on how to reproduce? I'm having a hard time replicating the issue.

#7 @wonderboymusic
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

No response in 12 months

Note: See TracTickets for help on using tickets.