Wordpress WP_Query where clause with OR?

前端 未结 4 476
梦谈多话
梦谈多话 2020-12-21 09:02

hello friends this is my args for WP_Query.

$args = array(\'post_type\' => \'job_listing\');
$args[\'meta_query\']=array(
   \'relation\' => \'OR\',
           


        
相关标签:
4条回答
  • 2020-12-21 09:41

    For the OR Query argument array should be like this:

    $args = array(
        'post_type' => 'post',
        'meta_query' => array(
            'relation' => 'OR',
            array(
                'key' => 'app_trailer-type',
                'value' => $job_tailor,
                'compare' => 'LIKE'
            ),
            array(
                'key' => 'app_pay-type',
                'value' => $app_pay_type,
                'compare' => 'LIKE'
            ),
            array(
                'key' => 'geo_address',
                'value' => $geo_address,
                'compare' => 'LIKE'
            ),
            array(
                'key' => 'geo_country',
                'value' => $geo_country,
                'compare' => 'LIKE'
            ),
            array(
                'key' => 'geo_short_address',
                'value' => $geo_short_address,
                'compare' => 'LIKE'
            ),
        )
    );
    

    Reference: http://codex.wordpress.org/Class_Reference/WP_Query

    0 讨论(0)
  • 2020-12-21 09:58

    From the WP_Query Class Reference (link):

    Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays) - you can see this in the second example below. This construct allows you to query multiple taxonomies by using the relation parameter in the first (outer) array to describe the boolean relationship between the taxonomy queries.

    You should add an array('relation' => 'OR') to the beginning of your meta_query array.

    0 讨论(0)
  • 2020-12-21 10:02

    changed args with like.

    $args = array('post_type' => 'job_listing', 'relation' => 'OR');
    $args['meta_query']=array(
        array(
            'key' => 'app_trailer-type',
            'value' => $job_tailor,
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'app_pay-type',
            'value' => $app_pay_type,
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'geo_address',
            'value' => $geo_address,
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'geo_country',
            'value' => $geo_country,
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'geo_short_address',
            'value' => $geo_short_address,
            'compare' => 'LIKE'
        ),
    );
    
    0 讨论(0)
  • 2020-12-21 10:03

    You may try something like this

    $args = array(
        'post_type' => 'job_listing',
        'meta_query' => array(
            'relation' => 'OR',
            array(
                'key' => 'app_trailer-type',
                'value' => $job_tailor,
                'compare' => 'LIKE'
            ),
            array(
                'key' => 'app_pay-type',
                'value' => $app_pay_type,
                'compare' => 'LIKE'
            ),
            // ....
        )
    );
    

    Read more on Codex.

    0 讨论(0)
提交回复
热议问题