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'd order post by meta_key but i've a problem with meta_value because is serialized object.

I'd order my post per count value.


I use below code but order correctly until wp version 3.4.2 after update to 3.5 order by date:

 if (have_posts()) :
    'meta_key' => 'tweets_count',
    'orderby' => 'meta_value',
    'showposts' => 10,
      while (have_posts()) : the_post();

stamp request:

REQUEST:SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 10


share|improve this question

Yes, it is possible, however your question is not really precise.

What you experience is probably already that it is possible to sort by meta_key even the value of it is a string of some serialized data - it's just that this is the standard binary sort and Wordpress does not take care about that this is a string with serialized data - it's just a string for the sort.

So the answer is: Yes, but this is not what you ask for.

Next to that answer, there is no feature built into Wordpress so far to search for some value inside a meta_value and then sort for that (sub) value.

It is required that you first get the whole result-set and then sort the data your own. This depends a bit on how you want to use it (you have not shared any code, so it is hard to say), technically there are multiple ways to do so.

share|improve this answer
I use a following code but works only until 3.4.2 version. if (have_posts()) : $args = array( 'posts_per_page' => 10, 'meta_key' => 'tweets_count', 'orderby' => 'meta_value', ); query_posts($args); while (have_posts()) : the_post(); // loop endif; – Marco Jan 18 '13 at 14:56
You should edit your question and put that information in there. Also specify more what "it does not work" means. That is not saying much (e.g. does your server has a bad day and it refuses the work?), better describe what exactly you expect and what exactly you get instead. E.g. by showing var_dump()s of important variables or picking error messages. Enable WP_DEBUG as well. – hakre Jan 18 '13 at 14:59
Thanks. I've edit my post – Marco Jan 18 '13 at 16:04

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.