gpt4 book ai didi

wordpress - 从 wp_get_archives 中排除类别?

转载 作者:行者123 更新时间:2023-12-03 07:01:40 30 4
gpt4 key购买 nike

有什么方法可以从 wp_get_archives 中排除某个类别吗?我试图在侧边栏中显示月份,但我想排除不是博客条目的帖子。

$catID = get_cat_id('Projects');
$variable = wp_get_archives('type=monthly&show_post_count=1);
echo $variable;

最佳答案

如果您只想在主题目录的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'";

}

关于wordpress - 从 wp_get_archives 中排除类别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2789228/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com