您可以在wp admin中添加自定义列以显示父类别。这是我的代码,你可以试试(我用post_type
是post
(默认值))。
// Add the custom columns to the post post type:
add_filter( \'manage_post_posts_columns\', \'set_custom_edit_post_columns\' );
function set_custom_edit_post_columns($columns) {
$columns[\'parent_cat\'] = __( \'Parent Category\', \'storefront\' );
return $columns;
}
// Add the data to the custom columns for the post post type:
add_action( \'manage_post_posts_custom_column\' , \'custom_post_column\', 10, 2 );
function custom_post_column( $column, $post_id ) {
if($column == \'parent_cat\'){
$terms = get_terms(\'category\');
foreach ($terms as $term) {
if($term->parent == 0){
echo $term->name;
}
}
}
}
以下是要查看的屏幕截图:
http://nimb.ws/RpoV8W