• I have a need to pull a query_posts similar to this:

    query_posts( array( 'post__not_in' => $do_not_duplicate , 'posts_per_page' => $count_non_sticky, 'paged' => get_query_var('paged'), 'cat' => '-944, -938') ); /* 944 Developments 938 AGM Announcements*/

    Except that instead of excluding all Posts belonging to either Categories 944 or 938, I want to exclude Posts that belong ONLY to either Category 944 and/or 938.

    What I am trying to achieve is to funnel Posts belonging ONLY to one of these categories off to a sidebar block. However if a Post belongs to one of these categories AND also to another one, then I don’t want it excluded from the main content query.

    The context is posts which are Announcements, for example. If a post is ONLY an Announcement, then I want it excluded from the main query so I can have it appear only in the Sidebar. But if it’s an Announcement and a Topic Of the Day, then I want it to appear in both he main body of Post Summaries AND the Sidebar.

    Does that make sense?

    Thank you for any help someone can provide.

Viewing 1 replies (of 1 total)
  • Thread Starter websherpa

    (@websherpa)

    As luck would have it, I stumbled upon my answer after posting. So I thought I’d post the result here to help anyone else with the same needs. I got my answer from here:

    http://wordpress.stackexchange.com/questions/2031/how-to-filter-post-from-categories-only-if-the-posts-appears-in-one-of-them-not

    With the resulting code:

    $allCategories = get_categories( array( ‘exclude’ => ‘944,938’ ) );
    $includeCategories = array();

    foreach ( $allCategories as $Bcategory )
    { $includeCategories[] = $Bcategory->term_id; }

    query_posts( array( ‘category__in’ => $includeCategories, ‘post__not_in’ => $do_not_duplicate , ‘posts_per_page’ => $count_non_sticky, ‘paged’ => get_query_var(‘paged’), ‘cat’ => ‘-1’) ); /* 944 Developments 938 AGM Announcements*/

Viewing 1 replies (of 1 total)
  • The topic ‘How to exclude Posts belonging to only ONE Category from query_posts()’ is closed to new replies.