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

Need help querying for posts with either one or another custom field.

Not sure how to use the 'or' operator here, but something like this the blow -

Have tried these:

share|improve this question

Your example is a bit hard to understand, as it seems to query for meta_values of X,Y,Z,AB,ID,IA. I hope you can still make sense of the below posted code:

// query posts that have on of the custom values for the custom meta key 'my_key' 
// and/or one of the custom meta values for the meta key 'your_key'
$posts = get_posts( array(
     'post_type' => 'my_post_type'
    ,'meta_query' => array(
             'key' => 'my_key'
            ,'value' => array( 'AB', 'ID', 'IA' )
            ,'compare' => 'IN'
             'key' => 'your_key'
            ,'value' => array( 'AB', 'ID', 'IA' )
            ,'compare' => 'IN'
) );

Other comparison values would be 'LIKE', 'NOT LIKE', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' where the later twos are reserved for numeric comparison and need an extra meta key/value pair: 'type' => 'numeric'.

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.