WordPress.org

Ready to get started?Download WordPress

Forums

Post with two categories - want to pull one (4 posts)

  1. sparkii
    Member
    Posted 5 months ago #

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

    and
    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?

  2. sparkii
    Member
    Posted 5 months ago #

    Anyone have any ideas for this one...

  3. mindctrl
    Member
    Posted 5 months ago #

    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' );

  4. sparkii
    Member
    Posted 5 months ago #

    @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

Reply

You must log in to post.

About this Topic