Opened 20 years ago
Closed 20 years ago
#1149 closed enhancement (fixed)
Need an "ORDER BY" query hook
Reported by: | davidchait | Owned by: | ryan |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 1.5.1 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
I already have a plugin using this to mimic my hacks in older WP code.
The basic theory is that plugins NEED to be able to control the ordering of the query results in order to do cute things like sticky posts, without the hack workaround of inserting a "1==0" into the query WHERE, then doing a second query 'the right way'. In the long run, there are other possible query hooks, but this is one I've got a post-ordering plugin ready for right now... :)
Easy change -- in classes.php, take the existing query line:
$request = " SELECT $distinct * ... ...
(currently around line 540, as of WP1.5)
And modify it, also adding two lines before it:
$orderby = "post_" . $qorderby?;
$orderby = apply_filters('posts_orderby', $orderby);
$request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1".$where." ORDER BY ".$orderby." $limits";
Feel free to modify names/etc. to suit your preferences.
-d
http://trac.wordpress.org/changeset/2466