• Hi,
    How can I exclude posts from category A except if they also belong to category B ?
    I used query_posts() to entirely exclude a category but it doesn’t allow that kind of conditional trick.
    pre_get_posts seems more flexible but I don’t know how to build the function to do this very job.
    Any idea is welcome …
    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter minutepapillon

    (@minutepapillon)

    Well, 5 seconds after posting this I had a simple idea : create a category called “exclude” so that I can exclude on a post by post base just by including the post in this category. My code doesn’t work. (I don’t do much PHP) Where is my error.
    Thanks

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	$cat_id1 = get_cat_ID('actualite');
    	$cat_id2 = get_cat_ID('exclure');
    	query_posts("cat=-$cat_id1,-$cat_id2&paged=$paged"); ?>
    Thread Starter minutepapillon

    (@minutepapillon)

    … solved :
    Just one “exclude” category is needed to do all this.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to exclude posts from category A except if they also belong to category B’ is closed to new replies.