Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have the following line to change my wp query slightly. The posts are by this ordered by the value in the custom field "wpfp_favorites". The value is allways an integer. Posts with value 0-9 is sorted correctly, but when a post has value 10 (or more i guess) its not listed above posts with 9.


What is wrong? You can see the problem in "action" here:

share|improve this question

1 Answer 1

up vote 4 down vote accepted

take a look here:

you need to change orderby=meta_value to orderby=meta_value_num -> than you value gets treated as an integer not a string!


i would pass an array instead of a string like

query_posts( array( 'meta_key'=>'wpfp_favorites', 'orderby'=>'meta_value_num' );

you dont have to but its easier to read and WordPress converts that string to an array anyway....

share|improve this answer
Thanks mate! That helped :-) – Espen Arnoy Oct 12 '10 at 12:34
glad i could help after so many people and times somebody has helped me... – chris Oct 12 '10 at 13:00

Your Answer


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