Function: sanitize_term_field

sanitize_term_field( string $field, string $value, integer $term_id, string $taxonomy, string $context )

Cleanse the field value in the term based on the context.

Shortcut: stf

You can use above key combination to trigger the associated snippet for this function in the WordPress Snippets for Visual Studio Code extension. You can also use this shortcut to search for this function on this website.

Passing a term field value through the function should be assumed to have cleansed the value for whatever context the term field is going to be used.

If no context or an unsupported context is given, then default filters will be applied.

There are enough filters for each context to support a custom filtering without creating your own filter function. Simply create a function that hooks into the filter you need.


Name Type(s) Default Value Description
$field string

Term field to sanitize.

$value string

Search for this term value.

$term_id integer

Term ID.

$taxonomy string

Taxonomy Name.

$context string

Context in which to sanitize the term field. Accepts 'edit', 'db', 'display', 'attribute', or 'js'.



Sanitized field.

WordPress Developer Newsletter

Stay informed of new chapter releases, important WordPress API updates and more.