[wp-hackers] Custom queries

Hannit Cohen hannit at codeart.co.il
Sun Mar 27 10:24:42 UTC 2011

I'm developing a real-estate site and need a custom search form.
The site search is based on price, number of rooms, location and
accommodation type (condo, appartment, etc...)

I'm using accommodation type and location as custom taxonomies.
price and # of rooms are special fields.

Here is the current custom search I'm using:
SELECT wposts.*
    FROM $wpdb->posts wposts
    LEFT JOIN $wpdb->postmeta price ON (wposts.ID = price.post_id AND
price.meta_key = 'price')
    LEFT JOIN $wpdb->postmeta rooms ON (wposts.ID = rooms.post_id AND
rooms.meta_key = 'rooms')
    LEFT JOIN $wpdb->term_relationships ON (wposts.ID =
    LEFT JOIN $wpdb->term_taxonomy ON
($wpdb->term_relationships.term_taxonomy_id =
    WHERE wposts.post_status = 'publish'
    AND price.meta_value BETWEEN  $pmin AND $pmax
    AND rooms.meta_value BETWEEN  $rmin AND $rmax
    AND $wpdb->term_taxonomy.taxonomy = 'category'
    AND $wpdb->term_taxonomy.term_id = $catid

I want to add the custom taxonomies select to this query (i.e. if I get
type=30) add that to the conditions.
since I have to custom taxonomies I need something that works for multiple
values with AND condition...

Any idea will be appreciated,

Hannit Cohen
hannit at codeart.co.il

More information about the wp-hackers mailing list