我需要幫助進行評論的搜索查詢(這是一個WordPress網站)。PHP/MySQL - 搜索查詢
評論中檢索該way-如果用戶登錄:
$comments = $wpdb->get_results($wpdb->prepare("
SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d
AND (comment_approved = '1' OR (user_id = %d AND comment_approved = '0'))
ORDER BY comment_date_gmt", $post->ID, $user_ID));
如果不是:
$comments = $wpdb->get_results($wpdb->prepare("
SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d
AND (comment_approved = '1' OR (comment_author = %s
AND comment_author_email = %s AND comment_approved = '0'))
ORDER BY comment_date_gmt",
$post->ID, wp_specialchars_decode($comment_author,ENT_QUOTES),
$comment_author_email));
,所以我我怎麼能過濾包含特定搜索字符串的意見,像$_GET['search_query']
?
這是WP的database structure。我在尋找搜索字符串是comment_content
謝謝,我會嘗試。順便說一句,百分號在$ _GET之前和之後做什麼? – Alex 2010-12-14 19:39:12