[wp-hackers] Custom queries

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


Hi,
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 =
$wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON
($wpdb->term_relationships.term_taxonomy_id =
$wpdb->term_taxonomy.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,
Thanks
Hannit

-- 
Hannit Cohen
CodeArt
+972-54-6280-490
hannit at codeart.co.il
http://codeart.co.il


More information about the wp-hackers mailing list