0

I'm having troubles to generate an sql query with operators.Actually wirte this code:

$args = array(
    'post_type' => 'listings',
    'posts_per_page' => 10,
    'paged' => $paged,  
    'meta_query' => array(
        //CITY
        array(
            'key' => 'city',
            'value' => $city,           
            'compare' => 'LIKE'
        ),    
        //type
        array(
            'key' => 'type',
            'value' => $type,           
            'compare' => 'LIKE'
        ),    
        //PRICE
        array(
            'key' => 'price',
            'value' => array( 100, 5000 ),          
            'compare' => 'BETWEEN'          
        ),      
    )
);

This code work fine, but now, i need to get the posts with price between $start and $end, OR price = -1. In other words, post that not have set the price, or set to -1 must show in the query. The others conditions (city, type,etc) must be match with AND

Any ideas? Thanks!

4

1 回答 1

0

我最初的想法是在posts_where 或posts_join 上添加一个过滤器,以便将自定义SQL 条件注入到查询中。

这些方面的东西:

wp_postmeta.meta_key='price' AND 
    (wp_postmeta.meta_value='-1' OR 
    CAST(wp_postmeta.meta_value AS INT) BETWEEN $start AND $end)
于 2013-09-24T19:49:01.263 回答