Treehouse: Grow your CSS skills. Land your dream job.

WordPress Custom Query Help

  • # November 17, 2011 at 2:41 pm

    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.


      < ?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) :
    • /< ?php echo $title; ?>">< ?php echo $title;?>

    • < ?php endforeach;?>
    # November 17, 2011 at 2:47 pm

    Maybe I’m not understanding exactly what you’re doing, but is there any reason why you’re not using query_posts?

    # November 17, 2011 at 3:00 pm

    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.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.