Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 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 );
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
add comment

Your Answer

 
discard

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.