I am trying to setup a custom Archives page and I am trying to obtain all Posts for a given page and loop through them and link them by title on the page, however I want to exclude a particular category (3) from the query, where am I going wrong with this, it is returning all posts for the month from both of my categories instead of just the one.
$titles = $wpdb->get_col(
"SELECT DISTINCT post_title FROM $wpdb->posts ".
"INNER JOIN $wpdb->terms AS t ".
"INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id ".
"INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id ".
"WHERE tr.term_taxonomy_id != 3 AND post_type = 'post' AND post_status = 'publish' AND MONTH(post_date) = '".$month."' AND YEAR(post_date) = '".$year."' ORDER BY post_date DESC"
foreach($titles as $title) :