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 unique situation where I need to filter on 2 custom fields where 1st field is expiry and values of "" and greater than todays date are valid and 2 field is a number which should be greater than some value. So Ideally I need to put a OR relation for 2 possibilities of 1st field with and between 1st field and second field.

Any help in this regard will be highly appreciated.

share|improve this question

that should be fairly simple using Meta_Query parameter of the WP_Query object

you can set the relation and set as many fields as you like:

$args = array(
'meta_query' => array(
        'relation' => 'OR', //realation 
            'key' => 'color', //first custom field
            'value' => 'blue',
            'compare' => 'NOT LIKE'
            'key' => 'price', //second custom field
            'value' => array( 20, 100 ),
            'type' => 'numeric',
            'compare' => 'BETWEEN'

$query = new WP_Query( $args );
share|improve this answer
I know about this but the problem is little more complex here. $args['meta_query'] = array( 'relation' => 'OR', array( 'key' => 'expiry', 'value' => $now , 'compare' => '>=' ), array( 'key' => 'expiry', 'value' => '' , 'compare' => '==' ), ); and I want to check these 2 inaddition to array ( 'key' => 'views', 'value' => '40', 'compare' => '>=') – Vijay Sharma Mar 18 '12 at 12:44

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.