get_term_by ( $field, $value, $taxonomy = '', $output = OBJECT, $filter = 'raw' )
- (string) $field Either 'slug', 'name', 'id' (term_id), or 'term_taxonomy_id'
- (string|int) $value Search for this term value
- (string) $taxonomy Taxonomy name. Optional, if `$field` is 'term_taxonomy_id'.
- (string) $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a WP_Term object, an associative array, or a numeric array, respectively. Default OBJECT.
- (string) $filter Optional, default is raw or no WordPress defined filter will applied.
Defined at:Change Log:
- (WP_Term|array|false) WP_Term instance (or array) on success. Will return false if `$taxonomy` does not exist or `$term` was not found.
- Introduced in WordPress: 2.3.0
- Deprecated in WordPress: —
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
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.
This function will always return the first term that matches the
$taxonomy combination specified in the parameters. If your query
is likely to match more than one term (as is likely to be the case when
$field is 'name', for example), consider using get_terms() instead; that
way, you will get all matching terms, and can provide your own logic for
deciding which one was intended.