小编Vic*_*a S的帖子

WordPress 类别不包括媒体附件

在 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 函数选项,但我不想自己创建,我想将其与现有类别分类法一起使用。

非常感谢任何对此的帮助。谢谢!

wordpress attachment count taxonomy categories

2
推荐指数
1
解决办法
1352
查看次数

标签 统计

attachment ×1

categories ×1

count ×1

taxonomy ×1

wordpress ×1