Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress Custom Query Help

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #35199
    mikes02
    Participant

    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) :
      ?>
    • /">


    #90861
    TheDoc
    Member

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

    #90864
    mikes02
    Participant

    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)
  • The forum ‘Back End’ is closed to new topics and replies.