0

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.

2

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);
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.