I'm trying to query the database for posts based on multiple custom fields. This is easy enough with the code below if values are simple:

 $querydetails = "
       SELECT wposts.*
       FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
       WHERE wposts.ID = wpostmeta.post_id
       AND wpostmeta.meta_key = 'field'
       AND wpostmeta.meta_value = 'value'
       AND wposts.post_status = 'publish'

But how do I query a value that is stored in array form, like a:1:{i:0;s:8:"value";} ?


3 Answers 3


You can't query the database for a value in the array. However you can grab the entire array and parse the array to get your value. Check out PHP ARRAY-VALUES. More than likely you'll need to use a for each statement.

Does the value your trying to get appear in the same spot in the array? If so it should be easier to target.

Good Luck!


Simply You can't because it is not possible!

about a year a go i asked that same question (almost) and the answer i got was

The only possible case when serialized data is acceptable is when you don't need to search or order by through that data.

So if your data is stored as serialized array you cant filter by it.


While the method in the question may not be possible, I realized that in my case, it's easier (and possible!) to modify the query rather than querying the database directly. The example below works for array format as it will find the string contained in it ('like' switch).

$args = array(
    'post_type' => 'termek',
    'meta_query' => array(
            'key' => 'property',
            'value' => 'value',
            'compare' => 'like'
            'key' => 'property',
            'value' => 'value',
            'compare' => '='
<?php query_posts($args); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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