[英]Mysql query not running with or condition
$query = $_GET['search'];
$wpdb->get_results("SELECT * FROM wp_posts WHERE (post_type = 'discussion' AND post_status = 'publish' AND (post_content like '%".$query."%' OR post_title like '%".$query."%))");
In this query OR
Condition is not running. 在此查询中OR
条件未运行。
Any help would be appreciated! 任何帮助,将不胜感激!
You missed a single quote in this place "%))");
您在此地方错过了单引号"%))");
. 。 So the working code will be: 因此,工作代码将是:
$wpdb->get_results("SELECT * FROM wp_posts WHERE (post_type = 'discussion' AND post_status = 'publish' AND (post_content like '%".$query."%' OR post_title like '%".$query."%'))");
The post_title like
having a starting '
but doesn't have the closing '
post_title like
有一个开始的'
但没有结尾的'
SQL command looks correct. SQL命令看起来正确。
If $query is really not empty you can try this (sometimes helps if you define returned type): 如果$ query确实不是空的,则可以尝试执行此操作(如果定义返回的类型有时会有所帮助):
$sql = 'your select';
$results = $wpdb->get_results($sql, OBJECT);
foreach ($results as $res) { ... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.