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 'orderby' => 'meta_value_num' to order some boats I have as a custom post type, the meta values ordered by, are boat models, which are normally just numbers but if you look at this page: http://boats-barcos.com/brands/ferretti/ you will see the ALTURA 840 is listed last when it should be between the 800 and 870. This is obviously because the value starts with a word. How can I get the orderby query to only order by the numerical value and ignore the word?

share|improve this question

If you look at the 50+ similar questions on Stack Overflow you'll see that you can only do so with considerable difficulty, and you won't have a very efficient query once you get it working. MySQL just isn't built to sort that way, and honestly the sort pattern you want is really very peculiar anyway. It isn't a normal sort by any standard.

And that is pure SQL. WP_Query is capable of much less finesse-- without the application of filters anyway.

Your best approach is going to be to normalize your data on insert, saving the numeric portion to one key and the rest elsewhere. Or force the number to the front followed by some marker like a comma that will let you juggle it back to the end on display.

share|improve this answer
Perfect solution in my opinion. model_number and series could be the two fields, display them together, but sort on model_number. Obviously the variables could be different names. – Eric Holmes Feb 24 '14 at 14:40

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.