Take the 2-minute tour ×
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.

query_posts('meta_key=wpfp_favorites&orderby=meta_value');

What is wrong? You can see the problem in "action" here: http://hverdagskupp.no/

share|improve this question

1 Answer 1

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!

query_posts('meta_key=wpfp_favorites&orderby=meta_value_num');

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

 
discard

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