WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

#9819 closed defect (bug) (fixed)

Allow order_by=none in query_posts

Reported by: joostdevalk Owned by: ryan
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.8
Component: Query Keywords: has-patch tested commit
Focuses: Cc:

Description

Would like to add an extra orderby value to query_posts, that could return posts based on the order they are in in it's include statement.

So when you do query_posts("include=3,2,5,4,1&orderby=none")

They are return in the order 3,2,5,4,1

Attachments (1)

9819.diff (532 bytes) - added by DD32 5 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 MichaelH5 years ago

Have seen this requested in the forums several times.


How about calling it 'orderby=explicit'?

Don't suppose using 'order=3,2,5,4,1' makes any sense?

comment:2 Denis-de-Bernardy5 years ago

order = false would be sweet. it would optimize the query, too.

comment:3 DD325 years ago

  • Keywords has-patch added
  • Version set to 2.8

How about calling it 'orderby=explicit'?

Explicit infers given order, Which brings it to

Don't suppose using 'order=3,2,5,4,1' makes any sense?

Not really.. Since a lot of the time the id's are not known until its queried.

order = false would be sweet. it would optimize the query, too.

False is an option, but empty(false) == true, which means changing the way its currently acting. Thats my reason for a vote for a string.

(This was also discussed on #wordpress-dev beforehand, And i was mentioning things to joostdevalk whilst he was writing this patch)

comment:4 Denis-de-Bernardy5 years ago

@dd: mmm, looks like you forgot to add the patch...

comment:5 DD325 years ago

@dd: mmm, looks like you forgot to add the patch...

Please use my full handle..

Sorry... I thought joostdevalk had added the patch.. I'll attach one now.

DD325 years ago

comment:6 DD325 years ago

  • Keywords needs-testing added

comment:7 Denis-de-Bernardy5 years ago

  • Keywords tested commit added; needs-testing removed

works fine

comment:8 ryan5 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [11415]) Add orderby=none. Props DD32. fixes #9819

comment:9 michaelh5 years ago

Cannot make this work so that it displays posts in the order of 3,2,5,4,1:

query_posts("include=3,2,5,4,1&orderby=none")

But this filter seems to work:

function filter_orderby($orderby = ) {

$orderby = " FIELD(ID, 3, 2, 5, 4, 1)";

return $orderby;

}

add_filter('posts_orderby', 'filter_orderby');

comment:10 daltonrooney4 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Type changed from enhancement to defect (bug)

This does not seem to work in WordPress 3.0.

comment:11 ryan4 years ago

We use this internally in WP and it seems to be working fine. All it means is that ORDER BY will not be in the query.

comment:12 daltonrooney4 years ago

I guess maybe I misunderstood michaelh's original request, then? When use this query

query_posts('include=1,3,2&orderby=none');

I get my posts back as 1,2,3

I actually need to get them back the way I entered it. Does that make sense?

comment:13 dd324 years ago

I think this may depend on your MySQL version..

But that being said, orderby=none IS ordering by the MySQL Natural ordering right now, which is ordered by insert time (So by ID basically).

comment:14 nacin4 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

This is correct. orderby=none does not fulfill the original request here.

However, this ticket has been closed for some time, and there was an enhancement to come out of it.

Adding orderby=provided (or what have you) can take place in a new ticket. If you wish to create one, be sure to reference #9819.

Closing.

Note: See TracTickets for help on using tickets.