Codex

Function Reference/get term by

Contents

Description

Get all Term data from database by Term field and data.

Warning: $value is not escaped for 'name' $field. You must do it yourself, if required.

The default $field is 'id', therefore it is possible to also use null for field, but not recommended that you do so.

If $value does not exist, the return value will be false. If $taxonomy exists and $field and $value combinations exist, the Term will be returned.

Usage

<?php get_term_by$field$value$taxonomy$output$filter ?>

Parameters

$field
(string) (required) Either 'slug', 'name', or 'id'
Default: None
$value
(string|integer) (required) Search for this term value
Default: None
$taxonomy
(string) (required) Taxonomy Name
Default: None
$output
(string) (optional) Constant OBJECT, ARRAY_A, or ARRAY_N
Default: OBJECT
$filter
(string) (optional) default is raw or no WordPress defined filter will applied.
Default: 'raw'

Return Values

(mixed) 
Term Row from database. Will return false if $taxonomy does not exist or $term was not found.

Examples

Notes

  • Warning: $value is not escaped for 'name' $field. You must do it yourself, if required.
  • See sanitize_term_field() The $context param lists the available values for 'get_term_by' $filter param.
  • Uses: sanitize_term() Cleanses the term based on $filter context before returning.
  • Uses global: (object) $wpdb

Change Log

Since: 2.3.0

Source File

get_term_by() is located in wp-includes/taxonomy.php.

Related

is_term, get_term, get_term_by, get_term_children, get_terms, wp_get_object_terms

See also index of Function Reference and index of Template Tags.