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 meta_query like this , but 'relation' => 'OR' NOT WORKING, Does meta_query only do 'both/and' checks and don't do 'either/or' ?

$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'OR',
    array(
        'key' => 'app_os',
        'compare' => 'LIKE',  
        'value' => 'iPhone',  
    ),
    array(
        'key' => 'app_os',
        'compare' => 'LIKE',  
        'value' => 'iPad',  
    )
)

); $query = new WP_Query( $args );

Thanks in advanced.

share|improve this question
add comment

2 Answers

meta_query works on 'both/and' checks and also 'either/or'.so don't worry.your coding was correct.this is the actual format...

$a = new WP_Query(
array(
    'fields' => 'ids',
    'ignore_sticky_posts' => true,
    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key' => 'foo',
            'value' => array( 'foobar' ),
            'compare' => 'IN'
        ),
        array(
            'key' => 'bar',
            'value' => array( 'foobar2' ),
            'compare' => 'IN'
        )
    )
) );
print_r( $a->posts );

you should try with this coding...

    $args=new WP_Query(
     array(
    'post_type' => 'post',
    'posts_per_page' => -1,
    'meta_query' => array(
    'relation' => 'OR',
        array(
            'key' => 'app_os',
            'value' => array('iPhone'),  
            'compare' => 'LIKE',  
        ),
        array(
            'key' => 'app_os_2',
            'value' => array('iPad') ,
            'compare' => 'LIKE',  

        )
    )
    ); 
print_r($args->posts);
share|improve this answer
add comment

Relation for meta queries is not available in current stable version. It should be supported in soon to be released version 3.2

See Introduce 'relation' arg to meta_query ticket on trac.

share|improve this answer
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.