OK, here’s the deal. I’m way outta my league, but am trying to construct a SQL statement and here’s what I have:
$querydetails = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wposts.post_status = 'publish'
AND wposts.post_type = 'page'
AND (
(wpostmeta.meta_key = 'available'
AND wpostmeta.meta_value = 'Yes'
)
OR
(wpostmeta.meta_key = 'bedrooms'
AND wpostmeta.meta_value = '2'
)
)
ORDER BY wposts.post_date DESC
";
I am trying to extract the records that are both AVAILABLE and have TWO BEDROOMS. This statement extracts ALL the records that are available in addition to the records that have two bedrooms. In fact, for each record that is both available and has two bedrooms it extracts the record TWICE.
It seemed logical to me to change the OR to and AND and that doing so would limit the records to those meeting both criteria. However, doing so actually causes an empty query to be returned.
What I would like to achieve is a list of records that are BOTH available and have two bedrooms. Any help much appreciated.