Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#2333 closed defect (bug) (invalid)

Controlling sort order with WP_rewrite in 2.0.x

Reported by: stewart@… Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.0
Component: General Keywords: rewrite
Focuses: Cc:


In the mod_rewrite world, you could control the sort order of various permalinks with rules like:

RewriteRule (.+)/?$ /index.php?category_name=$1&order=ASC [QSA,L]

There doesn't seem to be an equivalent in the super-duper new WP_Rewrite functions.

Change History (4)

#1 @ryan
16 years ago

It can be done with a plugin.

#3 @davidhouse
16 years ago

  • Resolution set to invalid
  • Status changed from new to closed

By hooking onto posts_orderby:

function force_desc($orderby) {
  $orderby = preg_replace('/ORDER BY ([^ ]+?) (ASC|DESC)?/', 'ORDER BY $1', $orderby);
  return $orderby

#4 @davidhouse
16 years ago

(Adding the missing line:)

add_filter('posts_orderby', 'force_desc');

Of course, the above func was just an example. You'd probably want to go for desc or asc based on some parameter.

Note: See TracTickets for help on using tickets.