0

I've a custom post type that has a custom filed called deck-number and client wants to sort the result by deck number. FYI, deck numbers are numeric values. So I used query like bellow.

get_posts('post_type=decks&nopaging=true&meta_key=deck-number&orderby=meta_value&order=ASC');

The issue I'm facing is I'm getting result sorting like 1, 10, 11, 12, 2, 3, 4, 5, 6, 7, 8, 9.

I need your advice to solve.

Thanks.

2

Use meta_value_num with orderby instead of meta_value.

meta_value is used to order alphabetically. meta_value_num used to order numerically.

For more information, check this: Codex get_posts And this for detailed information: Codex WP_Query

  • You saved my day :) – IFightCode Dec 5 '13 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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