0

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.

1 Answer 1

1

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 
        array(
            'key' => 'color', //first custom field
            'value' => 'blue',
            'compare' => 'NOT LIKE'
        ),
        array(
            'key' => 'price', //second custom field
            'value' => array( 20, 100 ),
            'type' => 'numeric',
            'compare' => 'BETWEEN'
        )
    )
);

$query = new WP_Query( $args );
1
  • 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' => '>=') Commented Mar 18, 2012 at 12:44

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.