我不确定这是否可行,但我希望能够在自定义帖子类型的管理区域中显示我的分类,以便WordPress用户可以对帖子进行排序,例如主题。
这是我自定义帖子类型和分类的代码
register_post_type( \'courses\',
array(
\'labels\' => array(
\'name\' => __( \'Courses\' ),
\'singular_name\' => __( \'Course\' )
),
\'public\' => true,
\'has_archive\' => false,
\'rewrite\' => array(\'slug\' => \'courses/%subject%\'),
)
);
}
function themes_taxonomy() {
register_taxonomy(
\'campuses\', // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
\'courses\', // post type name
array(
\'hierarchical\' => true,
\'label\' => \'Campuses\', // display name
\'query_var\' => true,
\'rewrite\' => array(
\'slug\' => \'campus\', // This controls the base slug that will display before each term
\'with_front\' => false // Don\'t display the category base before
)
)
);
register_taxonomy(
\'ages\', // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
\'courses\', // post type name
array(
\'hierarchical\' => true,
\'label\' => \'Ages\', // display name
\'query_var\' => true,
\'rewrite\' => array(
\'slug\' => \'ages\', // This controls the base slug that will display before each term
\'with_front\' => false // Don\'t display the category base before
)
)
);
register_taxonomy(
\'subject\', // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
\'courses\', // post type name
array(
\'hierarchical\' => true,
\'label\' => \'Subjects\', // display name
\'query_var\' => true,
\'rewrite\' => array(
\'slug\' => \'subjects\', // This controls the base slug that will display before each term
\'with_front\' => false // Don\'t display the category base before
)
)
);
} add_action( \'init\', \'themes_taxonomy\');
最合适的回答,由SO网友:Jacob Peattie 整理而成
As documented, 您可以设置show_admin_column
的参数register_taxonomy()
到true
为此,请执行以下操作:
\'show_admin_column\'
(bool)是否在其post类型列表屏幕上显示分类的列。默认值为false。
例如:
register_taxonomy(
\'subject\', // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
\'courses\', // post type name
array(
\'label\' => \'Subjects\', // display name
\'show_admin_column\' => true,
\'hierarchical\' => true,
\'query_var\' => true,
\'rewrite\' => array(
\'slug\' => \'subjects\', // This controls the base slug that will display before each term
\'with_front\' => false, // Don\'t display the category base before
),
)
);