get_term_by()

This WordPress function requires the CPT-onomy class.

Description

Get all CPT-onomy term data from database by term field and data.

Usage

$cpt_onomy->get_term_by( 						string
						$field
						, 						string|int
						$value
						, 						string
						$cpt_onomy
						, 						string
						$output
						, 						string
						$filter
						 );

Parameters

$field (string) (required)
Default: 'id'
Either 'slug', 'name', or 'id'.

$value (string|integer) (required)
Default: none
Search for this term value.

$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) Returns term row from database. Will return false if $cpt_onomy does not exist or $term was not found

Term object fields:

  • term_id
  • name
  • slug
  • term_group
  • term_taxonomy_id
  • taxonomy
  • description
  • parent
  • count

Examples

Get term data by the term's name:

global $cpt_onomy;
<?php $term = $cpt_onomy->get_term_by( 'name', 'Tom Hanks', 'actors' ); ?>

Get term data by the term's slug:

global $cpt_onomy;
<?php $term = $cpt_onomy->get_term_by( 'slug', 'tom-hanks', 'actors' ); ?>

WordPress Codex

For more information, refer to the WordPress codex.