wordpress - 带有 meta_query 和撇号的 Wordpress Wp_Query 搜索
问题描述
我正在使用名称中包含 ' 的 meta_query 值执行 Wp_Query。例如“角落的”。wp_query 的参数数组看起来像
$location_array = array(
'key' => 'hidden_address',
'value' => stripslashes ( sanitize_text_field( $_GET['adv_location'] ) ),
'compare' => 'LIKE',
'type' => 'char',
);
但是在搜索 "Corner's" 时查询返回 0 个结果。对于“角”返回正确的结果。
解决方案
帖子元被保存为角落的 - 所以解决方案是使用 htmlspecialchars
$value = stripslashes ( sanitize_text_field( $_GET['adv_location'] ) );
$value = htmlspecialchars($value,ENT_QUOTES );
$location_array = array(
'key' => 'hidden_address',
'value' => $value,
'compare' => 'LIKE',
'type' => 'char',
);
推荐阅读
- java - 为什么我们不能移动一个整数大于整数的大小?
- windows - 如何将 AD RMS 从 Windows Server 2012 升级到 Windows Server 2019
- vue.js - VueDX 警告:组件被推断为全局组件
- angular - 使用角度中的自定义按钮进行滑动分页/导航
- iis - Laravel5 iis 伪静态写法
- javascript - 在 react-testing-library 中触发两次点击事件
- apache - 请提供地理服务器建议 - HTTP 状态 400 - 错误请求
- git - Bitbucket 致命:无法读取“https://bitbucket.org”的用户名:没有这样的设备或地址
- c# - 实体框架核心包含(...在哪里)
- java - 从 GIF 图像读取 DPI 元数据