• On an archive page, I don’t want months that only contain posts from an excluded category to appear. As it stands, the month appears but says the page can’t be found. I’ve tried everything with no success. Actually I did have success with the following code (which I found here: https://www.ads-software.com/support/topic/wp_get_archives-and-conditional-tags?replies=6#post-1146474) but then the posts from the excluded category didn’t appear on the page I want them to. Sigh. Please help me. I will give you virtual cookies. Chocolate chip!

    add_filter('pre_get_posts','exclude_cat');
    add_filter( 'getarchives_where', 'customarchives_where' );
    add_filter( 'getarchives_join', 'customarchives_join' );
    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 = '3';
    return $x . " AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id NOT IN ($exclude)";
    }

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