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 a custom field value that is an array and it has date as one of the values:

a:3:{s:4:"date";s:10:"03/06/2013";s:6:"target";d:1000;s:8:"currency";s:3:"USD";}

I'm trying to sort posts with this date but I'm having trouble doing it.

Here is my query:

   $args = array (
            'showposts' => -1,
            'post_type' => 'project',
            'orderby' => 'meta_value',
            'order' => 'ASC',
            'meta_query'  => array(
                       array(
                        'key' => 'date',
                        'value' => date('m/d/Y'),
                        'compare' => '>=',
                        'type' => 'DATETIME',
                        )
                    ),
            'cat' => $cat_id);
        $posts = get_posts( $args );
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Sadly you can't.

You can't query based on serialized data and since you store the data in an array it is saved as serialized.

you should use a separate row for each field you want to query / sort based on.

I asked this same question about two years ago.

share|improve this answer
    
Thank you, i need to do it other way –  raaaa Mar 10 '13 at 15:04

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.