WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 14 months ago

#44762 new enhancement

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

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

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
14 months 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.