Posts Where Filter

add_filter( 'posts_where' , 'posts_where' );
function posts_where( $where ) {


if(!is_admin()){
global $wpdb;


if (isset($_GET['filter_state'])){
$filter_state = intval( $_GET['filter_state'] );
$where .= " AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id=$filter_state )";
}
if (isset( $_GET['filter_proff'])){
$childs = @implode(',',getChildCategories(intval($_GET['filter_proff'])));
$where .= " AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN($childs))";
}


if (isset( $_GET['filter_type'])){
$where .= " AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN(".$_GET['filter_type']."))";


}

}

return $where;
}