Ultimate Category Excluder
Exclude from Widgets? (5 posts)

  1. Andrew Tegenkamp
    Posted 2 years ago #

    This worked great to exclude a category from the archives but I also noticed I had a month where that was the only post and it showed on my archives widget. Plus it was still on my categories widget, so I wanted to offer up this code to exclude from the WP standard Categories and Archives widgets. If you have another method let me know, and I hope this helps!

    /* exclude categories from category widget */
    function exclude_widget_categories( $args ){
    	$args["exclude"] = '7'; //multiple = '7,8,9' using IDs from Posts=>Categories page in admin
    	return $args;
    /* exclude categories from archive list widget */
    function customarchives_join($x) {
    	global $wpdb;
    	return $x." INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
    function customarchives_where($x) {
    	global $wpdb;
    	$exclude='7'; //multiple = '7,8,9' using IDs from Posts=>Categories page in admin
    	return $x." AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id NOT IN ($exclude)";


  2. Michael Clark
    Posted 2 years ago #

    Thanks for the code. I'll play with it after I'm finished moving. Realistically it probably won't be experimented with until November.

  3. iwriteplays
    Posted 2 years ago #

    Thank you! This is exactly what I was looking for. Very helpful

  4. moonhopper
    Posted 2 years ago #

    Hi - looking interesting but I really need the solution Andrew appears to offer ... where do you place that code Andrew? Do you have to manually edit those IDs in there or is there an admin panel/plug-in method for that?

    Thanks in anticipation

  5. Fra Calo
    Posted 2 years ago #

    childtheme functions.php (@moonhopper)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Ultimate Category Excluder
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic