$querystr = "
SELECT DISTINCT wposts.*
FROM $wpdb->posts wposts
LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id)
WHERE wposts.post_status = 'publish'
AND wposts.post_type = 'post' AND wposts.ID IN (
SELECT DISTINCT object_id
FROM $wpdb->term_relationships
WHERE $wpdb->term_relationships.term_taxonomy_id = 3)
".(!empty($_POST['search']['city']) ?
"AND wposts.ID IN (
SELECT DISTINCT object_id FROM $wpdb->term_relationships
WHERE $wpdb->term_relationships.term_taxonomy_id = ".$_POST['search']['city'].")":"")."
".(!empty($_POST['search']['service']) ?
"AND wposts.ID IN (
SELECT DISTINCT object_id FROM $wpdb->term_relationships
WHERE $wpdb->term_relationships.term_taxonomy_id = ".$_POST['search']['service'].")":"")."
".(!empty($_POST['search']['budget']) ?
"AND wposts.ID IN (
SELECT object_id
FROM wp_term_relationships
WHERE term_taxonomy_id IN (
SELECT term_taxonomy_id
FROM wp_term_taxonomy
WHERE term_id = ".$_POST['search']['budget']." AND taxonomy = 'post_tag'))":"")."
ORDER BY wposts.post_date DESC";
$pageposts = $wpdb->get_results($querystr, OBJECT);
Hey guys,
Im trying to create a custom post search/filter query on my site. Basically all the posts belong to 3 categories, and will have certain tags. All posts will share one category (3, hardcoded), the other 2 can be different between posts and are provided by $_POSTs.
The problem im having is that $_POST['search']['service'] cause the query to not work. If only $_POST['search']['budget'] and $_POST['search']['city'] are provided, then its fine. Anyone know if there's an easy solution? thansk.