treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] WordPress Custom Query Help

  • 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.
                    	<ul>
    <?php
    $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) :
    ?>
    <li><a href="<?php bloginfo('url'); ?>/<?php echo $title; ?>"><?php echo $title;?></a></li>
    <?php endforeach;?>
    </ul>
  • Maybe I'm not understanding exactly what you're doing, but is there any reason why you're not using query_posts?
  • Because I'm a moron and didn't think that would work, lol, but it worked just fine, it always ends up being the easiest thing, thanks for pointing me in the right direction.