Make WordPress Core

Opened 20 years ago

Closed 20 years ago

#1149 closed enhancement (fixed)

Need an "ORDER BY" query hook

Reported by: davidchait's profile davidchait Owned by: ryan's profile 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

Change History (2)

#1 @davidchait
20 years ago

  • Patch set to No

#2 @ryan
20 years ago

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