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

a:2:{s:5:"count";d:9750;s:7:"timeout";i:1358466733;}

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

 if (have_posts()) :
    $args=array(
    'meta_key' => 'tweets_count',
    'orderby' => 'meta_value',
    'showposts' => 10,
      ); 
      query_posts($args);
      while (have_posts()) : the_post();
//loop

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

Thanks.

share|improve this question
add comment

1 Answer 1

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
add comment

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.