• Resolved arijit14

    (@arijit14)


    Hi,
    I have a problem with multiple meta keys not working together. I have 100 posts and they have 1 meta key is price and 1 meta key is price type. in price we store prices and price type we store Fixed, Negotiable, ON Call. here the on call posts are not showing with the price filter. If user search by price range 100 to 500 then I need to show on call posts but not showing. The on call posts price field is blank. So how I show on call posts with price range. Here is the query

    $args = array(
    ‘s’ => $title,
    ‘post_type’ => ‘ad_post’,
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => 100, //New Custom Code
    ‘post__in’ => (!empty($postArr))? $postArr : [],
    ‘tax_query’ => array(
    $category,
    $ad_types,
    ),
    ‘meta_query’ => [
    ‘relation’ => ‘AND’,
    $price,
    $custom_search,
    [
    ‘relation’ => ‘OR’,
    $priceType,
    ],
    ],

    ‘order’ => $order,
    ‘orderby’ => $orderBy,
    ‘paged’ => $paged,
    );

    $price = array(
    ‘key’ => ‘price’,
    ‘value’ => array($_GET[‘min_price’], $_GET[‘max_price’]),
    ‘type’ => ‘numeric’,
    ‘compare’ => ‘BETWEEN’,
    );

    $priceType = array(
    ‘key’ => ‘price_type’,
    ‘value’ => array(‘Negotiable’,’Fixed’,’on_call’),
    ‘compare’ => ‘IN’
    );

    I have also tax_query so all combination not working together.
    So I need to display on call post with price range filter. Always price filter remove price type filter.
    Which post have on call then in postmeta table has price = blank and price_type = on_call
    and which ad have price type = Fixed and price = 100 or some other value.

    Please help.

Viewing 1 replies (of 1 total)
  • What is in $custom_search ?

    I would recommend to make the meta_query simpler, especially without “OR”:

    'meta_query' => [
    'relation' => 'AND',
    $price,
    $priceType,
    ],
    ],

    This will search for all products in the range that have one of the price types. If you only want to have “on_call”, limit the array in $priceType accordingly.

Viewing 1 replies (of 1 total)
  • The topic ‘Multiple meta key provide wrong result’ is closed to new replies.