Make WordPress Core

Opened 22 years ago

Closed 22 years ago

#1149 closed enhancement (fixed)

Need an "ORDER BY" query hook

Reported by: davidchait Owned by: ryan
Priority: normal Milestone:
Component: General Version: 1.5.1
Severity: normal Keywords:
Cc: Focuses:

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

Change History (2)

#1 @davidchait
22 years ago

  • Patch → No

#2 @ryan
22 years ago

  • fixed_in_version → 1.5.1
  • Owner changed from anonymous to rboren
  • Resolution 10 → 20
  • Status new → closed
Note: See TracTickets for help on using tickets.