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 have a metafield, that contains a series of options and writes the results to an array in a single meta field:


I find posts that contain any of the array elements, and display them using WP_Query

$search = new WP_Query('meta_key=mykey&meta_value=second');

But this doesn't seem to work. Any idea on how to achieve this?

I have edited my method, following this question:

$arg['meta_key'] == $key;
$args['meta_value'] = "%|".$value."|%";
$custom_query = new WP_Query($args);

But no darts.

share|improve this question
up vote 2 down vote accepted

I believe you have to use meta compare LIKE. If you do a regular meta query, the resulting SQL will be meta_value = your_value, which is never going to find anything because it's trying to match the entire contents of the field.

share|improve this answer

I'm pretty sure to return or search an array for values (or keys) you need to use meta_query

So something like:

$search = array(
           'post_type' => 'post',
           'meta_query' => array(
                                   'key'     => 'mykey',
                                   'value'   => 'second',

 $query = new WP_Query($search);
share|improve this answer
No joy I am afraid. – Mild Fuzz Aug 17 '11 at 15:50

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.