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 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',

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?


share|improve this question

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() ) :
    echo '<li>' . get_the_title() . '</li>';

// Restore original Query & Post Data

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


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.