#7205 closed enhancement (fixed)
Adds 'orderby' support to Activity queries
Reported by: | Mamaduka | Owned by: | tw2113 |
---|---|---|---|
Milestone: | 2.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Activity | Keywords: | has-patch commit |
Cc: |
Description
Currently BP_Activity_Activity::get()
doesn't support 'orderby' query arg. ORDER BY
is hardcoded to 'date_recorded'.
It would be nice to introduce something similar that WP core query classes are doing, since 4.2 - https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/.
Attachments (3)
Change History (13)
#1
@
8 years ago
- Keywords 2nd-opinion needs-testing removed
- Milestone changed from Awaiting Review to Future Release
- Type changed from defect (bug) to enhancement
#4
@
8 years ago
Patch looks good, @tw2113!
Instead of the array_key_exists()
check, maybe switch() would be better?
<?php switch ( $r['order_by'] ) { case 'id' : case 'user_id' : case 'component' : case 'all the other DB columns!': break; default : $r['order_by'] = 'date_recorded'; break; }
#5
@
8 years ago
Amended to use a switch statement and decided to add all the columns, since it could be feasible that someone wanted to order by hide_sitewide or by spam status. Originally I left the last 4 off.
Definitely possible. Something to keep in mind is that we current order by 2 items. date_recorded column and then activity ID. We should probably leave activity ID as the 2nd order by.
First up would be providing a parsed value for the method. I feel we should have it default to what we have now. Since it's never been changeable before, I'm unsure there's much back compat to break.
Second part, that I think we should do, is only allow values from the current columns through. So we'd need to do some sort of comparison or array value checks from our allowed columns. Perhaps fall back to date_recorded if the user-provided value isn't valid.
See attachment for consideration.