Function Reference/get term link
Languages:
English •
(Add your language)
Description
Returns permalink for a taxonomy term archive, or a WP_Error object if the term does not exist.
Usage
<?php get_term_link( $term, $taxonomy ); ?>
Parameters
- $term
- (object/int/string) (required) The term object / term ID / term slug whose link will be retrieved.
- Default: None
- $taxonomy
- (string) (required) The taxonomy slug. NOT required if you pass the term object in the first parameter
- Default: None
Return Values
- URL (string)
- URL to taxonomy term archive.
- WP_Error (object)
- Error if term does not exist.
Examples
$terms = get_terms('species');
echo '<ul>';
foreach ($terms as $term) {
echo '<li><a href="'.get_term_link($term->slug, 'species').'">'.$term->name.'</a></li>';
}
echo '</ul>';
Notes
- Uses: apply_filters() Calls 'term_link' filter on the finished link.
- Uses global: (unknown) $wp_rewrite
- Since the term can be an object, int, or string make sure that any numbers you pass in are explicitly converted to an integer. (int)$myID
- term->term_id doesn't currently work for the $term parameter. See this trac ticket for more info.
- PHP may halt if you attempt to print an error result ("Catchable fatal error: Object of class WP_Error could not be converted to string"). Use is_string() to check the result of this function if you are not sure the term exists.
Change Log
Source File
get_term_link() is located in wp-includes/taxonomy.php.
Related
Categories:
the_category(),
the_category_rss(),
single_cat_title(),
category_description(),
wp_dropdown_categories(),
wp_list_categories(),
get_the_category(),
get_the_category_by_ID(),
get_category_by_slug(),
get_the_category_list(),
get_category_parents(),
get_category_link(),
is_category(),
in_category()