Support » Fixing WordPress » Post with two categories – want to pull one

  • I have a post which has a Cat ID of 8 and a Cat ID of 1

    In my child template I want to pull posts in a specific category, those with Cat ID of 8, so I’m using

    query_posts ('cat=8&order=ASC')

    – this works great for posts which have only one category, but when a post has two categories, it fails.

    I worked up a query in MySQL to be sure I could actually get both posts, and I can do that but I don’t understand why the above doesn’t query_post does not work.

    P.S. I also tried excluding all the Cat ID’s but 8:

    query_posts ('cat=-1,-3,-4,-5&order=ASC')

    query_posts( 'category__in=8&order=ASC' )

    but all failed.

    Can someone help me understand what is going on here and point me to where I can find a solution?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Anyone have any ideas for this one…

    John Parris



    It’s recommended by the core developers to not use query_posts. Use WP_Query instead. You should be able to do something like this:
    $query = new WP_Query( 'cat=1,8' );

    @mindctri Thanks for the advice.

    I take a closer look at WP_Query. I do close my query after every call using wp_reset_query(); so maybe I’m okay

    It turns out my issue was a caching issue. The first query is right…it didn’t make sense to me that it would not be working. So I experiment with some weird css (e.g. giving a pink background to my content) and and I didn’t see that on the page, I knew something else was up.

    I had WP_Cache installed originally when the site was just a site. When I switched to wpmu, I turned all plugins off. WP_Cache is still off/deactivated on the network and on each individual site but there must be I did with WP_Cache as it is still caching pages

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post with two categories – want to pull one’ is closed to new replies.