Support » Fixing WordPress » Excluding category from archive month list (getarchives_join filter)

  • Resolved Simon Blackbourn

    (@lumpysimon)


    Hi

    I need to exclude a category (ID 36) from the archives, so that months do not show in the wp_get_archives list if they only contain posts from that category. It looks like I need to use the getarchives_join filter, but my SQL is a bit ropey and I’ve got stuck.

    I’ve got this in my functions.php:


    add_filter( 'getarchives_join', 'no_cat36_in_archives' );

    function no_cat36_in_archives( $join ) {

    global $wpdb;

    $join = "INNER JOIN {$wpdb->prefix}term_relationships ON ({$wpdb->prefix}posts.ID = {$wpdb->prefix}term_relationships.object_id)
    INNER JOIN {$wpdb->prefix}term_taxonomy
    ON ({$wpdb->prefix}term_relationships.term_taxonomy_id = {$wpdb->prefix}term_taxonomy.term_taxonomy_id)
    WHERE 1=1
    AND {$wpdb->prefix}term_taxonomy.taxonomy = 'category'
    AND {$wpdb->prefix}term_taxonomy.term_id <> 36";

    return $join;

    }

    but now no archive months are showing at all. Can anyone help me out with the SQL I need to exclude category 36 from the archives?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Excluding category from archive month list (getarchives_join filter)’ is closed to new replies.