Exclude posts on advanced search
-
I’m trying to exclude Posts that are under category “Multi-Family”. Users can choose home plans and drill down as to # of beds, # bath, foundation, etc. All that works fine. The problem is that users want to choose between Single Family and Multi-Family. There is no category for Single Family. So, to get only the Single Family content, I have to exclude “Multi-Family”. Here is my code for doing that – but it does not work – can anyone tell me why – or point me in the right direction – I am new to WordPress:
$dwelling_option gets its setting from <option><option> in another php file which does work. There is one other PHP file, but it is for display only.
//Dwelling Type
if ( (!empty($dwelling_options)) AND (!empty($dwelling_options )) )
{
$filter_flag = true;
$keyss = ”;
if(count($post_ids_meta) > 0) {
foreach($post_ids_meta as $val) {
$keyss .= $val.’,’;
}
$keyss = trim($keyss , “,”);
}
if(!empty($keyss)) {$post_ids_meta = $wpdb->get_col( $wpdb->prepare( ” SELECT DISTINCT wp_posts.ID FROM wp_posts
LEFT JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id )
LEFT JOIN wp_term_taxonomy ON ( wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id )
WHERE wp_term_taxonomy.taxonomy = ‘category’
AND wp_term_relationships.term_taxonomy_id != 108
AND wp_term_taxonomy.term_id = “.$dwelling_options.”
AND wp_posts.post_status = ‘publish’
AND wp_posts.post_id IN (“.$keyss.”) “));
}
else {
$post_ids_meta = $wpdb->get_col( $wpdb->prepare( ” SELECT DISTINCT wp_posts.ID FROM wp_posts
LEFT JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id )
LEFT JOIN wp_term_taxonomy ON ( wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id )
WHERE wp_term_taxonomy.taxonomy = ‘category’
AND wp_term_taxonomy.term_id = “.$dwelling_options.”
AND wp_posts.post_status = ‘publish’ “) );
}
}Appreciate your help
The topic ‘Exclude posts on advanced search’ is closed to new replies.