我们正在编写一个自定义搜索功能,按照给定的术语搜索帖子 OR Post Meta OR post_title
我们有多个术语和Post Meta值,我们正在寻找在少数元和术语值上应用 OR 操作的解决方案 .
吼叫是我们到目前为止的查询,但是当然,我们没有按照我们的要求工作
$search_keyword = $_GET['search_keyword'];
$args = array(
'post_type' => 'product',
'post_title' => $search_keyword,
'tax_query' => array(
array(
'taxonomy' => 'property-city',
'terms' => $search_keyword,
'field' => 'slug',
'operator' => 'LIKE'
),
array(
'taxonomy' => 'property-type',
'terms' => array('sale', 'rent'),
'field' => 'slug',
'operator' => 'IN'
)
),
'meta_query' => array(
array(
'key' => 'min_beds',
'value' => '2',
'compare' => '>=',
),
array(
'key' => 'min_baths',
'value' => '1',
'compare' => '>=',
),
array(
'key' => 'address',
'value' => $search_keyword,
'compare' => 'LIKE',
)
)
);
$the_query = new WP_Query($args);
$search_keyword
包含需要搜索的字符串值 . 并且只应选择那些具有与给定的 $search_keyword
OR 匹配的元键的帖子,其中术语 OR 与帖子 Headers 匹配
另外,保持其他条件不变 .
注意:关系b / w Taxonomy property-type
和Post Meta min_beds/min_baths
应为 AND
1 回答
我很确定这是不可能的 . 您可以编写自定义SQL,也可以只执行两到三次查询并合并结果 - 这可能是最简单的 .