从wp_get_archives中排除类别?

Nor*_*ert 3 wordpress archive categories

有没有办法从wp_get_archives中排除某个类别?我试图在侧边栏中显示月份,但我想排除不是博客条目的帖子.

$catID = get_cat_id('Projects');
$variable = wp_get_archives('type=monthly&show_post_count=1);
echo $variable;
Run Code Online (Sandbox Code Playgroud)

小智 5

如果要在主题目录的functions.php中仅包含wp_get_archive函数的特定类别,请使用此选项

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;

    $includes= '14'; // category id to include
    return $x . " AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id = '$includes'";

}
Run Code Online (Sandbox Code Playgroud)