Make WordPress Core

Opened 16 years ago

Last modified 4 years ago

#14368 reopened enhancement

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

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

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 16 years ago.

Download all attachments as: .zip

Change History (19)

#1 @wjm
16 years ago

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

#2 @wjm
16 years ago

  • Keywords has-patch added

#3 follow-up: @scribu
16 years ago

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

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

Replying to scribu:

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

exactly

#5 @scribu
16 years ago

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

#6 @scribu
16 years ago

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

#7 @scribu
16 years ago

  • Milestone Awaiting Review → 3.1

#8 @ryan
16 years ago

  • Keywords 3.2-early added
  • Milestone 3.1 → Future Release

We'll do this in 3.2.

#9 @scribu
16 years ago

  • Keywords 3.2-early removed
  • Milestone Future Release → 3.2

#10 @greenshady
16 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
16 years ago

  • Milestone 3.2 → Future Release

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

#12 @SergeyBiryukov
15 years ago

  • Milestone Future Release → 3.3

#13 @ryan
15 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
15 years ago

  • Milestone 3.3 → Future Release

#15 @nacin
14 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
14 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
13 years ago

  • Milestone Future Release
  • Resolution → maybelater
  • Status new → 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
4 years ago

  • Resolution maybelater
  • Status closed → 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.