Wordpress 搜索功能,还可以在帖子的自定义字段中搜索关键字
wp中的默认搜索功能仅搜索帖子/页面的内容。但是我有一些分类,上面有自定义字段的帖子(我使用了高级自定义字段插件),我尝试使用许多插件作为relevansi,但仍然没有找到在自定义字段中搜索的方法。也许我错过了什么。如何获得包含自定义字段的搜索结果?请帮忙。像这样试试Wordpress 搜索功能,还可以在帖子的自定义字段中搜索关键字,wordpress,search,advanced-custom-fields,Wordpress,Search,Advanced Custom Fields,wp中的默认搜索功能仅搜索帖子/页面的内容。但是我有一些分类,上面有自定义字段的帖子(我使用了高级自定义字段插件),我尝试使用许多插件作为relevansi,但仍然没有找到在自定义字段中搜索的方法。也许我错过了什么。如何获得包含自定义字段的搜索结果?请帮忙。像这样试试 function custom_search_where($where) { // put the custom fields into an array $customs = array('custom_field1', 'cu
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');
你能展示你的实现代码吗?@BindiyaPatoliya实际上我的意思是wp中的默认搜索,它在帖子内容中搜索查询……Sorry会尝试让你知道。谢谢。:)