我一直在尝试使用SELECT
.. WHERE
.. IN
global $wpdb;
$sql = "SELECT * FROM wp_search WHERE name IN ('s','w','a')";
$result = $wpdb->get_results ( $sql );
if ( $result )
{
print_r($result);
}
但它失败并返回错误。有没有替代这个Select语句或我需要做的任何其他事情来使这个功能按预期进行?
答案 0 :(得分:0)
您的代码对我来说绝对正常但是您可以参考此替代
global $wpdb;
$special_entries = array( 'inherit', 'auto-draft', 'unanswered' );
$how_many = count($special_entries);
$placeholders = array_fill(0, $how_many, '%s');
$format = implode(', ', $placeholders);
$query = "SELECT * FROM $wpdb->posts WHERE post_status IN($format)";
$results = $wpdb->get_results( $wpdb->prepare($query, $special_entries) );