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 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: http://hverdagskupp.no/

share|improve this question
up vote 4 down vote accepted

take a look here: http://codex.wordpress.org/Function_Reference/query_posts

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.