0

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 );
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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