WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 6 days ago

#18616 reopened enhancement

WP_Query Order by Taxonomy

Reported by: justindgivens Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.2.1
Component: Query Keywords: has-patch needs-testing 2nd-opinion
Focuses: Cc:

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)

query.diff (1.7 KB) - added by justindgivens 4 years ago.

Download all attachments as: .zip

Change History (6)

@justindgivens4 years ago

comment:1 @justindgivens4 years ago

  • Keywords needs-testing added

comment:2 @scribu4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed
Version 0, edited 4 years ago by scribu (next)

comment:3 @justindgivens4 years ago

Scribu, thanks for the quick turn. Also thanks for those articles.

comment:4 @marsjaninzmarsa9 days ago

  • Keywords 2nd-opinion added
  • Resolution wontfix deleted
  • Status changed from closed to 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).

comment:5 @SergeyBiryukov6 days ago

  • Milestone set to Awaiting Review
Note: See TracTickets for help on using tickets.