[Support request] How to apply three columns to a custom post type taxonomy

Home Forums Support [Support request] How to apply three columns to a custom post type taxonomy

Home Forums Support How to apply three columns to a custom post type taxonomy

Viewing 5 posts - 16 through 20 (of 20 total)
  • Author
    Posts
  • #1946624
    Takeru

    I would also like to know the code for multiple slugs such as “yumeshizuku”.
    For example, “yumeshizuku” and “koshihikari”.

    #1946631
    Takeru

    Is there any code that can make all slugs belonging to a specific taxonomy display the same way?

    #1947610
    Elvin
    Staff
    Customer Support

    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;
    }
    #1947736
    Takeru

    It’s perfect!
    Thank you so much!

    #1947809
    Elvin
    Staff
    Customer Support

    No problem. Glad to be of any help. 😀

Viewing 5 posts - 16 through 20 (of 20 total)
  • You must be logged in to reply to this topic.