Opened 15 years ago
Closed 10 years ago
#18616 closed enhancement (wontfix)
WP_Query Order by Taxonomy
| Reported by: | justindgivens | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Query | Version: | 3.2.1 |
| Severity: | normal | Keywords: | has-patch needs-testing 2nd-opinion close |
| Cc: | Focuses: |
Description
To be able to order by a taxonomy for any post type.
Added:
'orderby' => 'tax'
'tax_name' => 'taxonomy_name'
This way you can sort the post by the Term->name (ASC/DESC) value.
It was something needed in one of my projects and thought the WP community might like it.
Attachments (1)
Change History (9)
#4
@
11 years ago
- Keywords 2nd-opinion added
- Resolution wontfix
- Status closed → reopened
Otto had a point, but had it 4 years ago - now we have sticky posts and other custom implementations of the same concept for CPT based on taxes, what with it?
If I wanna show my "Promoted" posts on the top I must create two separate WP_Querys, or manually play with SQL via hooks, or rearrange posts array after query (last one only if I can bear sticking on each page separately, what's not right solution in some cases).
#6
@
11 years ago
- Keywords close added
I'd be totally +1 for this, but because it still requires three joins (wp_term_relationships for terms related to the posts, wp_term_taxonomy to restrict by taxonomy, wp_terms to get the term name).
However, there are solutions in the form of snippets and maybe even plugins -- that can add this functionality. So I'd say, for performance reasons, this should be closed. Three joins is an awful lot on a very large database of posts with heavy use of terms.
This ticket was mentioned in Slack in #core by boone. View the logs.
10 years ago
#8
@
10 years ago
- Milestone Awaiting Review
- Resolution → wontfix
- Status reopened → closed
As @sc0ttkclark notes, there are performance concerns with this suggestion.
Performance aside, it's not clear how the feature would be implemented in a consistent way. A post object may be associated with more than one term in a taxonomy. When that's the case, how does the sorting work?
Closing, pending someone who wants to do the dirty work to demonstrate how the feature would work in practice.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Thanks for the patch, but this is not something we want in Core. Here's a thorough explanation from Otto:
http://wordpress.stackexchange.com/questions/14306/using-wp-query-is-it-possible-to-orderby-taxonomy/14309#14309