1

wp 中的默认搜索功能仅搜索帖子/页面的内容。但是我的类别中有带有自定义字段的帖子(我已经使用了高级自定义字段插件)。我尝试使用许多插件作为 Relevanssi,但仍然没有找到在自定义字段中搜索的方法。也许我错过了一些东西。如何获取包含自定义字段的搜索结果?请帮忙。

4

1 回答 1

2

像这样试试

function custom_search_where($where) {
// put the custom fields into an array
$customs = array('custom_field1', 'custom_field2', 'custom_field3');

foreach($customs as $custom) {
$query .= " OR (";
$query .= "(m.meta_key = '$custom')";
$query .= " AND (m.meta_value  LIKE '{$n}{$term}{$n}')";
    $query .= ")";
}

$where = " AND ({$query}) AND ($wpdb->posts.post_status = 'publish') ";
return($where);
}
add_filter('posts_where', 'custom_search_where');
于 2014-02-08T06:26:21.823 回答