Description
Get all CPT-onomy term data from database by term ID.
To retrieve term data by name, slug or ID, use get_term_by() instead.
Usage
$cpt_onomy->get_term( int|object $term, string $cpt_onomy, string $output, string $filter );
Parameters
$term (integer|object) (required)
Default: none
If integer, will get term data from database. If object, will apply filters and return $term.
$cpt_onomy (string) (required)
Default: none
Name of the CPT-onomy that the term belongs to.
$output (string) (optional)
Default: OBJECT
Constant OBJECT, ARRAY_A, or ARRAY_N.
$filter (string) (optional)
Default: 'raw'
Default is raw or no WordPress defined filter will be applied.
Return Values
(mixed|null|WP_Error) Returns term row from database. Will return null if $term is empty and a WP_error object if the $cpt_onomy does not exist.
Term object fields:
- term_id
- name
- slug
- term_group
- term_taxonomy_id
- taxonomy
- description
- parent
- count
Examples
Print the term's name:
<?php global $cpt_onomy; $term = $cpt_onomy->get_term( $term_id, 'actors' ); echo $term->name; ?>
Print the term's name with its term archive link:
<?php
global $cpt_onomy;
$term = $cpt_onomy->get_term( $term_id, 'actors' );
if ( !empty( $term ) ) {
echo '<a href="' . $cpt_onomy->get_term_link( $term, $term->taxonomy ) . '">' . $term->name . '</a>';
}
?>
Related Functions
get_term_by(), get_term_children(), get_term_link(), get_terms(), term_exists(), wp_get_object_terms()
WordPress Codex
For more information, refer to the WordPress codex.
