在 WordPress 中,我正在创建一个画廊,它将自动显示所选类别及其子类别中的新图像。我已经设置了类别,以便它们适用于使用以下内容的媒体:
register_taxonomy_for_object_type( 'category', 'attachment' );
Run Code Online (Sandbox Code Playgroud)
现在我需要这样做,以便类别能够计算相关附件而不仅仅是帖子。我找到了这个链接How to Override default update_count_callback forcategory with this code:
function change_category_arg() {
global $wp_taxonomies;
if ( ! taxonomy_exists('category') )
return false;
$new_arg = &$wp_taxonomies['category']->update_count_callback;
$new_arg->update_count_callback = 'your_new_arg';
}
add_action( 'init', 'change_category_arg' );
Run Code Online (Sandbox Code Playgroud)
但到目前为止我还没有弄清楚(不确定它是否不起作用或者我是否只是不理解某些东西,例如“your_new_arg”是什么)。我在注册新分类法时确实找到了 update_count_callback 函数选项,但我不想自己创建,我想将其与现有类别分类法一起使用。
非常感谢任何对此的帮助。谢谢!