Custom Search, MySql Query Gone Wrong?

This doesn’t seem especially complex, but does seem bulky and prone to errors.

As I answered couple of times on similar issues – if this isn’t time critical then wait for WP 3.1 because it will have major improvements for querying by custom fields.

See Advanced Metadata Queries for brief writeup on upcoming improvements.

For sanitizing queries see $wpdb->prepare() method – Protect Queries Against SQL Injection Attacks.