Support » Plugin: Posts in Page » Category Exclusion

  • I’m trying to use your plugin to display posts that are NOT in specific categories.

    I started with something like this:
    [ic_add_posts showposts="4" orderby="post_date" order="DESC" template="recents_template.php" category="-2,-4,-9,-12,-13,-344" ignore_sticky_posts="no"]

    That didn’t work so I started digging around and I found this reference to an exclude_category option, but that didn’t work either.

    Is this currently possible?
    Thanx a bunch for any help you can provide. 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor anvilzephyr


    Hi Jon,
    Did you use slugs in your exclude_category argument? It doesn’t work with ids.

    • This reply was modified 2 years, 10 months ago by anvilzephyr.
    Thread Starter Jon Hardison


    I tried everything and nothing worked. 🙁

    What I ended up doing (probably stupid) was modifying the class-page-posts.php.
    I remarked out the bit that wasn’t working and added the following:

    // new exclude posts with certain categories by id
    	if ( isset( $atts['exclude_category'] ) ) {
    		$exclude_category = explode( ',', $atts['exclude_category'] );
    	if ( isset( $this->args['cat'] ) ) {
    		$this->args['cat'] = array_merge( $this->args['cat'], $exclude_category );
    	} else {
    		$this->args['cat'] = $exclude_category;

    This let me do it using categoty ids with “-” like wordpress does natively.
    Don’t kill me.
    I had to do something cuz I was on a deadline, but I would like to figure out why what was there didn’t work.

    It DID work when I entered only one category but failed to filter by any category with 2 or more specified.

    Does that help?

    This is the section I remarked out:

    		// exclude posts with certain category by name (slug)
    //		if ( isset( $atts['exclude_category'] ) ) {
    //			$category = $atts['exclude_category'];
    //			if ( strpos( ',', $category ) ) {
    // multiple
    //				$category = explode( ',', $category );
    //				foreach ( $category AS $cat ) {
    //					$term = get_category_by_slug( $cat );
    //					$exclude[] = '-' . $term->term_id;
    //				}
    //				$category = implode( ',', $exclude );
    //			} else {
    // single
    //				$term = get_category_by_slug( $category );
    //				$category = '-' . $term->term_id;
    //			}
    //			if ( ! is_null( $this->args['cat'] ) ) {
    // merge lists
    //				$this->args['cat'] .= ',' . $category;
    //			}
    //			$this->args['cat'] = $category;
    //			// unset our unneeded variables
    //			unset( $category, $term, $exclude );
    //		}
    • This reply was modified 2 years, 10 months ago by Jon Hardison.
    Plugin Contributor anvilzephyr


    Definitely not stupid but it will be overwritten so it would be good to figure this out. Do you remember what you used in the shortcode that failed? My tests worked so maybe I can reproduce using your exact shortcode. Thanks

    Thread Starter Jon Hardison


    Sorry. I swore I responded to this but it doesn’t look like it took for some reason. The first example was pretty close:

    [ic_add_posts showposts="4" orderby="post_date" order="DESC" template="recents_template.php" exclude_category="category-1,category-2,category-3" ignore_sticky_posts="no"]

    This didn’t work at all. If I used the option to exclude a single category it worked fine:

    [ic_add_posts showposts="4" orderby="post_date" order="DESC" template="recents_template.php" exclude_category="category-1" ignore_sticky_posts="no"]

    So it seems the problem is limited to the declaration of multiple categories for exclusion.

    I’m having the same problem

    I have the same issue. Exluding one category works fine. Excluding multiple categories does not appear to work.

    [ic_add_posts exclude_category='slug1,slug2,slug3,slug4,slug5' showposts='10' orderby='date' order='DESC']

    I’m running WP 4.9.7 (and Enfold theme 4.4)

    Any ideas on the above?

    As a workaround I’ve created another category called ‘exclude’ which I assign as a second category to any posts I want to exclude. I then can get away with just excluding this one category.

    It’s not ideal though. I’d love someone to suggest a proper fix so that exclude_cargory could take multiple args.

    Thanks in advance!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Category Exclusion’ is closed to new replies.