Support » Fixing WordPress » Q about excluding categories

  • Hi

    This morning ran into a situation where a category was excluded in a query_posts statement yet was appearing on the page anyway. It turned out the post was in two categories. One was excluded but the other was included. So WP included the post because it passed the test of being in a category that was not excluded, even though one category WAS excluded. This is a reasonable solution to this situation, but in this particular case it was the exact opposite of the behavior I needed from WP.

    I played with exclude=-11 and category__not_in=11 and could not find a way to make it work. I resolved it by putting an if (in_category('11')) continue at the top of the loop which caused WP to skip over that post and not display it, but that seemed like a kludge solution.

    Wonder if anyone has worked out a solution or code for this situation.
    thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Can’t think of any other way to do what you want other than the solution you proposed.

    Guess you’d need a new kind of argument for query_posts, something like ‘exclude_regardless_of_other_categories=11’.

    Thanks Michael. I’d never had a need for this until yesterday, and I couldn’t come up with anything better myself.

    More like “thanks for nothing” would be appropriate!

    Guess there’s always creating your own wpdb type query…though the MySQL statement would be an interesting thing to figure…

    Starting point:

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Q about excluding categories’ is closed to new replies.