自定义分类不会显示在网格视图中,用于‘附件’帖子类型

时间:2020-03-06 作者:Dominique Pijnenburg

我在内置的附件帖子类型中添加了一个名为“颜色”的分类法。在编辑“列表”视图中的项目时,我可以看到分类法,但在使用“网格”视图时,我无法看到/使用分类法的术语。

列表视图:list view

网格视图:grid view

我希望分类法也显示在网格视图中,但不明白为什么它不这样做。

这是我注册自定义分类法的代码:

function nij_register_taxonomies() {
    $taxonomy_names = array(
        \'singular\' => __( \'Color\', \'stufig\' ),
        \'plural\'   => __( \'Colors\', \'stufig\' )
    );

    register_taxonomy( strtolower($taxonomy_names[\'singular\']),
        array(\'attachment\'),
        array(
            \'labels\'            => array(
                \'name\'              => sprintf( _x( \'%s\', \'taxonomy general name\', \'stufig\' ), $taxonomy_names[\'plural\'] ),
                \'singular_name\'     => sprintf( _x( \'%s\', \'taxonomy singular name\', \'stufig\' ), $taxonomy_names[\'singular\'] ),
                \'search_items\'      => sprintf( __( \'Search %s\', \'stufig\' ), $taxonomy_names[\'plural\'] ),
                \'all_items\'         => sprintf( __( \'All %s\', \'stufig\' ), $taxonomy_names[\'plural\'] ),
                \'parent_item\'       => sprintf( __( \'Parent %s\', \'stufig\' ), $taxonomy_names[\'singular\'] ),
                \'parent_item_colon\' => sprintf( __( \'Parent %s:\', \'stufig\' ), $taxonomy_names[\'singular\'] ),
                \'edit_item\'         => sprintf( __( \'Edit %s\', \'stufig\' ), $taxonomy_names[\'singular\'] ),
                \'update_item\'       => sprintf( __( \'Update %s\', \'stufig\' ), $taxonomy_names[\'singular\'] ),
                \'add_new_item\'      => sprintf( __( \'Add New %s\', \'stufig\' ), $taxonomy_names[\'singular\'] ),
                \'new_item_name\'     => sprintf( __( \'New %s Name\', \'stufig\' ), $taxonomy_names[\'singular\'] ),
                \'menu_name\'         => sprintf( __( \'%s\', \'stufig\' ), $taxonomy_names[\'plural\'] )
            ),
            \'public\'            => false,
            \'hierarchical\'      => true,
            \'show_ui\'           => true,
            \'show_admin_column\' => true,
            \'query_var\'         => true,
            \'show_in_nav_menus\' => true,
            \'show_tagcloud\'     => false,
            \'update_count_callback\' => \'_update_generic_term_count\',
            // \'rewrite\'           => array(),
        )
    );
}

add_action( \'init\', \'nij_register_taxonomies\', 11 );

1 个回复
SO网友:Himad

设置参数publictrue 可以。签出文件wp-admin/includes/media.php, 作用get_compat_media_markup() 供参考:

if ( $args[\'in_modal\'] ) {
    foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
        $t = (array) get_taxonomy( $taxonomy );

        if ( ! $t[\'public\'] || ! $t[\'show_ui\'] ) {
            continue;
        }

相关推荐