WordPress.org

Ready to get started?Download WordPress

Forums

Q about excluding categories (4 posts)

  1. stvwlf
    Member
    Posted 5 years ago #

    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

  2. MichaelH
    Member
    Posted 5 years ago #

    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'.

  3. stvwlf
    Member
    Posted 5 years ago #

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

  4. MichaelH
    Member
    Posted 5 years ago #

    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:
    Displaying_Posts_Using_a_Custom_Select_Query

Topic Closed

This topic has been closed to new replies.

About this Topic