WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the following code to display an archive dropdown:

    wp_dropdown_categories( 'taxonomy=week&hierarchical=1&orderby=name' );

However the format of the taxonomy is week-1, week-2 .... week-10, week-11 I need it to be natural orderered as per http://www.php.net/manual/en/function.natsort.php e.g.

Week 1
Week 2
Week ...
Week 10
Week 11

Currently it's being ordered true alpha e.g.

Week 1
Week 10
Week 11
Week 2

Not sure what the best way to do this is, any help or thoughts much appreciated.

share|improve this question
up vote 1 down vote accepted

not the best way (at least if you have a lot of tags)

add_filter('get_terms_orderby', 'get_terms_orderby_natural_slug',10,2);
wp_dropdown_categories( 'taxonomy=week&hierarchical=1&orderby=slug' );
remove_filter('get_terms_orderby', 'get_terms_orderby_natural_slug');

function get_terms_orderby_natural_slug($orderby, $args){
    $orderby = "SUBSTR({$orderby} FROM 1 FOR 5), CAST(SUBSTR({$orderby} FROM 6) AS UNSIGNED), SUBSTR({$orderby} FROM 6)";
    return $orderby;

but still this is a way to do that...

share|improve this answer
This is an interesting solution, however numbers less than 10 are sorted inverse, e.g. week 9, week 8, week ..., week 1, week 10 – Jona Nov 14 '12 at 15:07
should work now. – qwerty qwerty Nov 14 '12 at 15:11
Brilliant, thanks very much. – Jona Nov 14 '12 at 15:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.