WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 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:

Description

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)

comment:1 ryan8 years ago

It can be done with a plugin.

comment:2 stewart8 years ago

How?

comment:3 davidhouse8 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
}

comment:4 davidhouse8 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.