简体   繁体   中英

How to filter search results without using IN operator in SQL request in PHP script

I use search filters (from Mikado) and I have problem with sql + php statement.

$where[] = "{$wpdb->prefix}terms.slug IN (".implode(', ', array_fill(0, count($this->tourTypes), '%s')).")";

This line allow to dynamic display trips which have: category1 OR category2 OR category3.

I would like to change it for something like: category1 AND category2 AND category3.

Do you know any alternatives for IN? What the data format in new query should be?

I'd keep it simple:

$catConds = [];
for($i=0; $i <= count($this->tourTypes); $i++) {
    $catConds[] = "{$wpdb->prefix}terms.slug = $i";
}

$where[] = implode(' AND ', $catConds);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM