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'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";} ?

share|improve this question
Search for meta_query here on WPSE. – kaiser Mar 7 '12 at 9:47
up vote 0 down vote accepted

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!

share|improve this answer

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.

share|improve this answer

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); ?>
share|improve this answer

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.