Opened 4 years ago

Closed 3 years ago

#9819 closed defect (bug) (fixed)

Allow order_by=none in query_posts

Reported by: joostdevalk Owned by: ryan
Priority: normal Milestone: 2.8
Component: Query Version: 2.8
Severity: normal Keywords: has-patch tested commit
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 4 years ago.

Download all attachments as: .zip

Change History (15)

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?

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

comment:3   DD324 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)

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

comment:5   DD324 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.

DD324 years ago

comment:6   DD324 years ago

  • Keywords needs-testing added
  • Keywords tested commit added; needs-testing removed

works fine

comment:8   ryan4 years ago

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

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

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');

  • 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.

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.

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?

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).

  • 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.