Hi,
I'm having a question about Types.
I was wondering if it is possible to add a column for your custom taxonomy on a custom post type overview in the back end.
Eg: I have created a custom post type called 'products' and a custom taxonomy 'brands'. I would like to be able to see what 'brand' a product has from the product overview. Similar to how the posts overview page works really. This is especially useful if you have lots of posts, otherwise you always have to check via the quick edit function what category the post is under.
Additionally: is it possible to add a sorting function to the top of the overview page (again, similar to the native posts overview) where you can sort per category?
If anyone can point me in the right direction it would be much appreciated!
Dear Eva,
This is in our requests list, but it hasnt been scheduled yet. Meanwhile you can use the code suggested in this post:
https://toolset.com/forums/topic/add-taxonomy-filter-to-admin-posts-menu/#post-12956
Here we are using articles and publication in the same way you want.
Please let me know if there is anything else that I can assist you with.
Regards,
Caridad
Thanks for your fast response!
I'm taking you have to substitute the 'publication' in the example with the slug of your custom taxonomy. I tried that with two separate themes but it doesn't seem to work. Am i doing something wrong? > see code below, my custom taxonomy is called 'secties' (slug).
function add_new_columns($defaults) {
$defaults['secties'] = 'Secties';
return $defaults;
}
function add_column_data( $column_name, $post_id ) {
if( $column_name == 'secties' ) {
$terms = get_the_terms( $post_id, 'secties' );
if ( !empty( $terms ) ) {
$out = array();
foreach ( $terms as $c ) $out[] = $c->name;
echo implode( ', ', $out );
} else {
echo 'Not published';
}
}
}
add_filter( 'manage_article_posts_columns', 'add_new_columns' );
add_action( 'manage_posts_custom_column', 'add_column_data', 10, 2 );
Dear Eva,
You also have to replace article with the slug of your custom type. This is part of the name of the filter.
Please let me know if there is anything else that I can assist you with.
Regards,
Caridad
Ah, i missed that one. Thank you very much for your help!
rober-
Thanks for the tip on the CodePress Admin Columns. Just tried it out and worked perfectly!!