[wp-trac] [WordPress Trac] #44762: Suggested changes to get_cat_name and get_cat_link to provide support for custom taxonomies
WordPress Trac
noreply at wordpress.org
Thu Aug 9 10:53:19 UTC 2018
#44762: Suggested changes to get_cat_name and get_cat_link to provide support for
custom taxonomies
----------------------------+-----------------------------
Reporter: geoffcourtauld | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version:
Severity: minor | Keywords:
Focuses: |
----------------------------+-----------------------------
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
<?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
<?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;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44762>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list