Make WordPress Core

Opened 6 years ago

Last modified 6 years ago

#44762 new enhancement

Suggested changes to get_cat_name and get_cat_link to provide support for custom taxonomies

Reported by: geoffcourtauld's profile geoffcourtauld Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: Taxonomy Keywords: needs-patch
Focuses: Cc:

Description

I discovered today that these functions only support the taxonomy 'category'. Can I suggest something along the following lines so that a custom taxonomy can easily be used?:

<?php
        function get_cat_name( $cat_id, $tax_type ) {
                $cat_id = (int) $cat_id;
                if ( isset($tax_type) ) $tax_type = $tax_type;
                        else $tax_type = 'category';
                $category = get_term( $cat_id, $tax_type );
                if ( ! $category || is_wp_error( $category ) )
                        return '';
                return $category->name;
        }
<?php
        function get_cat_link( $category, $tax_type ) {
                if ( ! is_object( $category ) )
                        $category = (int) $category;
                if ( isset($tax_type) ) $tax_type = $tax_type;
                        else $tax_type = 'category';
                $category = get_term_link( $category, $tax_type );                                       
                if ( is_wp_error( $category ) )
                        return '';                       
                return $category;
        }

Change History (1)

#1 @sebastienserre
6 years ago

  • Keywords needs-patch added

Hello, and welcome
of course you can purpose something by creating a patch and submitting it here.

Note: See TracTickets for help on using tickets.