Make WordPress Core

Opened 14 years ago

Last modified 2 years ago

#14368 reopened enhancement

make the 'orderby' argument in get_posts() accept all "post" fields

Reported by: wjm's profile wjm Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Query Keywords: has-patch
Focuses: Cc:

Description

Right now, some post's fields were not accepted when retrieving posts (even though they were documented in codex . for example "name" (slug) was missing).

this patch sorts the elements in the $allow_keys array (in the same order as the db' s columns) and adds the missing ones, I added every field except the ones that were long text fields (content, excerpt, etc)

Attachments (1)

query_allowed_keys.patch (1.2 KB) - added by wjm 14 years ago.

Download all attachments as: .zip

Change History (19)

#1 @wjm
14 years ago

sorry, i missed it in the title.
This only has to do with SORTING the results by these fields mentioned.

#2 @wjm
14 years ago

  • Keywords has-patch added

#3 follow-up: @scribu
14 years ago

Your description is not really clear. Do you mean the accepted values for the 'orderby' argument?

#4 in reply to: ↑ 3 @wjm
14 years ago

Replying to scribu:

Your description is not really clear. Do you mean the accepted values for the 'orderby' argument?

exactly

#5 @scribu
14 years ago

  • Summary changed from make get_posts() accept all "post" fields to make the 'orderby' arguement in get_posts() accept all "post" fields

#6 @scribu
14 years ago

  • Summary changed from make the 'orderby' arguement in get_posts() accept all "post" fields to make the 'orderby' argument in get_posts() accept all "post" fields
  • Type changed from defect (bug) to enhancement

#7 @scribu
14 years ago

  • Milestone changed from Awaiting Review to 3.1

#8 @ryan
14 years ago

  • Keywords 3.2-early added
  • Milestone changed from 3.1 to Future Release

We'll do this in 3.2.

#9 @scribu
14 years ago

  • Keywords 3.2-early removed
  • Milestone changed from Future Release to 3.2

#10 @greenshady
13 years ago

+1 for this.

I needed to order some book/movie titles alphabetically the other day by slug (post_name field) because some titles have "a," "an," and "the" in them. The slug doesn't have these words.

I'll be glad to help with this if needed.

#11 @jane
13 years ago

  • Milestone changed from 3.2 to Future Release

Didn't make it in by freeze. Can shoot for 3.3.

#12 @SergeyBiryukov
13 years ago

  • Milestone changed from Future Release to 3.3

#13 @ryan
13 years ago

Since orderby is in WP::public_query_vars, we probably want to make sure all available orderbys perform well lest they become DOS potentials.

#14 @ryan
13 years ago

  • Milestone changed from 3.3 to Future Release

#15 @nacin
12 years ago

Seems like the big one here is "name", right?

Not sure comment_status or ping_status is all that useful — they only store two values, and are also often overridden by filters (including in core).

mime_type is interesting. post_type is a bit weird from the semantic perspective that different types aren't exactly meant to be combined into one feed, and sorting them via the raw name is weird. Same goes for status.

date_gmt and modified_gmt seem unnecessary, given date and modified.

#16 @RDALL
12 years ago

If I am to understand both the Codex and the function properly… Then I would also suggest Menu Order as the get post field can order by "menu order" and not just by name.

#17 @wonderboymusic
11 years ago

  • Milestone Future Release deleted
  • Resolution set to maybelater
  • Status changed from new to closed

name was added in [18838] - I am going to close, those other fields aren't indexed, someone reopen if you really need to sort by mime

#18 @pbiron
2 years ago

  • Resolution maybelater deleted
  • Status changed from closed to reopened

I have a need to sort by post_excerpt.

It's not hard to hook into posts_orderby to achieve this, but it really should be handled by WP_Query.

Note: See TracTickets for help on using tickets.