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/


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....

  • glad i could help after so many people and times somebody has helped me...
    – chris
    Oct 12 '10 at 13:00

Your Answer

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