query fails, returns 0.
-
I’m working on a search function which should search the database for the keywords a user enters in a textfield. For some reason I can’t get this query to work, it keeps returning 0.
Also the escaping of LIKE statement doesnt seem to work either. My guess is that the function is deprecated as I get this back.
“Fatal error: Call to undefined method wpdb::esc_like()“
// Place the search keywords in array $keywords = explode(' ', $_POST['keywords']); $where = ''; foreach($keywords as $keyword) { // $keyword = esc_like($keyword); - function deprecated? $where .= " post_title LIKE '%" . $keyword . "%' OR post_content LIKE '%" . $keyword . "%' OR"; } // Remove last 'OR' $where = substr($where, 0, -2); // The sql $sql = " SELECT * FROM wp_posts WHERE (" . $where . ") AND post_type = '%s' AND post_status = '%s' ORDER BY post_date DESC "; $query = $wpdb->query( $wpdb->prepare($sql, array('post', 'publish')) ); print_r($query);
Any help is appreciated
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘query fails, returns 0.’ is closed to new replies.