Archived topic
How to apply three columns to a custom post type taxonomy
19 replies · Started by Takeru on September 28, 2021
I would also like to know the code for multiple slugs such as "yumeshizuku".
For example, "yumeshizuku" and "koshihikari".
Is there any code that can make all slugs belonging to a specific taxonomy display the same way?
Is there any code that can make all slugs belonging to a specific taxonomy display the same way?
You can certainly do this.
Example:
add_filter( 'generate_blog_columns','tu_products_columns' );
function tu_products_columns( $columns ) {
$term = get_queried_object();
$taxonomy = $term->taxonomy;
$termSlug = $term->slug;
if ( is_post_type_archive( 'products' ) || $taxonomy == 'kind' ) {
return true;
}
return $columns;
}
The condition if ( is_post_type_archive( 'products' ) || $taxonomy == 'kind' ) checks if the current page is of products post type archive of products or is of taxonomy kind.
If you want to add multiple custom post type, you simply change is_post_type_archive( 'products' ) to is_post_type_archive( array( 'products', 'another_post_type_1', 'another_post_type_slug_2' ) ).
If you want to include multiple taxonomies, create an array listing all the taxonomies you want and then have it checked by in_array() function instead of using $taxonomy == 'kind'.
Example:
add_filter( 'generate_blog_columns','tu_products_columns' );
function tu_products_columns( $columns ) {
$term = get_queried_object();
$taxonomy = $term->taxonomy;
$termSlug = $term->slug;
$tax_list_included = array('kind','another_taxonomy1' ,'another_taxonomy2');
if ( is_post_type_archive( 'products' ) || in_array($taxonomy, $tax_list_included) ) {
return true;
}
return $columns;
}
It's perfect!
Thank you so much!
No problem. Glad to be of any help. :D