Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

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. –  Oleg Butuzov Nov 14 '12 at 15:11
    
Brilliant, thanks very much. –  Jona Nov 14 '12 at 15:14
add comment

Your Answer

 
discard

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.