我正在尝试获取某些 post_types 的结果,但是,当我添加过滤器以检查 post_title 和 post_content 是否为“LIKE”查询字符串时,将返回所有 post_types,包括附件 post_types,我不希望显示在$args。这是我正在尝试的代码:
$query_string = get_search_query();
$args = array(
'post_type' => array("hc_pillow", "hc_topper", "hc_accessory", "page"),
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'tab_retail',
'value' => $query_string,
'compare' => 'LIKE'
),
array(
'key' => 'tab_tech',
'value' => $query_string,
'compare' => 'LIKE'
),
array(
'key' => 'tab_shipping_information',
'value' => $query_string,
'compare' => 'LIKE'
)
),
'posts_per_page' => "-1"
);
function filter_where_title($where = '') {
$query_string = get_search_query();
$where .= " OR post_title LIKE '%".$query_string."%' OR post_content LIKE '%".$query_string."%'";
return $where;
}
$posts = new WP_Query();
add_filter('posts_where', 'filter_where_title');
$posts->query($args);
remove_filter('posts_where', 'filter_where_title');
任何帮助都将不胜感激,我不确定还有什么可以尝试的。,