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 use following array and works fine... sort post by meta_key where value of t_count is a number:

$args = array(
 'posts_per_page' => 10,
 'meta_key' => 't_count',
  'orderby' => 'meta_value',
   );
      query_posts($args);

I use 3.4.2 but if I upgrade to 3.5 array above do not sort correctly.

I've try also meta_value_num but do not works fine.

Could you help me?

Thanks

share|improve this question

1 Answer 1

Try WP_Query() instead of query_posts()

$args = array(
   'posts_per_page' => 10,
   'meta_key' => 't_count',
   'orderby' => 'meta_value_num',
   'order' => 'ASC'
 );

// The Query
$the_query = new WP_Query( $args );

// The Loop
while ( $the_query->have_posts() ) :
    $the_query->the_post();
    echo '<li>' . get_the_title() . '</li>';
endwhile;

// Restore original Query & Post Data
wp_reset_query();
wp_reset_postdata();

Above code should work!

share|improve this answer
    
Thanks @Furqan but do not works. Example meta_value array stored a:2:{s:5:"count";d:31714;s:7:"timeout";i:1358206247;} –  Marco Jan 14 '13 at 22:56
    
are you using "WPAlchemy MetaBox PHP Class" ? –  Furqan Jan 15 '13 at 13:50
    
No, I use: update_post_meta( $post_id, 't_count', $meta ); –  Marco Jan 15 '13 at 17:51
    
yes! 'orderby' => 'meta_value_num' is only work with single value not with serialized array. i think you have to hack this but i have no idea about this. another solution is have a look at this video youtube.com/watch?v=5i6nOSVOBaY use wpalchemy-metabox (farinspace.com/wpalchemy-metabox) –  Furqan Jan 15 '13 at 20:18

Your Answer

 
discard

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

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