Wordpress, multiple meta_key in pre_get_posts

后端 未结 2 2000
情书的邮戳
情书的邮戳 2020-12-30 11:35

is it possible to add two meta_key\'s in pre_get_posts?

my current query

$query->set(\'s\', \'\' ); 
$q         


        
2条回答
  •  天命终不由人
    2020-12-30 12:17

    You can convert this query to pre_pget_posts:

    $meta_query_args = array(
        'relation' => 'AND', // "OR"
        array(
            'key'     => '_my_custom_key',
            'value'   => 'Value I am looking for',
            'compare' => '='
        ),
        array(
            'key'     => '_your_min_model_key',
            'value'   => 1453,
            'compare' => '>'
        ),
        array(
            'key'     => '_your_max_model_key',
            'value'   => 1923,
            'compare' => '<'
        )
    );
    $meta_query = new WP_Meta_Query( $meta_query_args );
    

    And compare param details:

    compare (string) - Operator to test. Possible values are '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'EXISTS' (only in WP >= 3.5), and 'NOT EXISTS' (also only in WP >= 3.5). Values 'REGEXP', 'NOT REGEXP' and 'RLIKE' were added in WordPress 3.7. Default value is '='. 
    

提交回复
热议问题