且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 wp_get_archives 中排除类别?

更新时间:2023-08-26 21:06:22

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

Use this if you want to include only specific categories for wp_get_archive function in your functions.php of your theme directory

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'";

}