Title: taxonomy_meta_box_sanitize_cb_input
Published: February 22, 2019
Last modified: August 20, 2026

---

# taxonomy_meta_box_sanitize_cb_input( string $taxonomy, array|string $terms ): array

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/taxonomy_meta_box_sanitize_cb_input/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/taxonomy_meta_box_sanitize_cb_input/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/taxonomy_meta_box_sanitize_cb_input/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/taxonomy_meta_box_sanitize_cb_input/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/taxonomy_meta_box_sanitize_cb_input/?output_format=md#changelog)

Sanitizes POST values from an input taxonomy metabox.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/taxonomy_meta_box_sanitize_cb_input/?output_format=md#parameters)󠁿

 `$taxonomy`stringrequired

The taxonomy name.

`$terms`array|stringrequired

Raw term data from the `'tax_input'` field.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/taxonomy_meta_box_sanitize_cb_input/?output_format=md#return)󠁿

 array

## 󠀁[Source](https://developer.wordpress.org/reference/functions/taxonomy_meta_box_sanitize_cb_input/?output_format=md#source)󠁿

    ```php
    function taxonomy_meta_box_sanitize_cb_input( $taxonomy, $terms ) {
    	/*
    	 * Assume that a 'tax_input' string is a comma-separated list of term names.
    	 * Some languages may use a character other than a comma as a delimiter, so we standardize on
    	 * commas before parsing the list.
    	 */
    	if ( ! is_array( $terms ) ) {
    		$comma = _x( ',', 'tag delimiter' );
    		if ( ',' !== $comma ) {
    			$terms = str_replace( $comma, ',', $terms );
    		}
    		$terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
    	}

    	$clean_terms = array();
    	foreach ( $terms as $term ) {
    		// Empty terms are invalid input.
    		if ( empty( $term ) ) {
    			continue;
    		}

    		$_term = get_terms(
    			array(
    				'taxonomy'   => $taxonomy,
    				'name'       => $term,
    				'fields'     => 'ids',
    				'hide_empty' => false,
    			)
    		);

    		if ( ! empty( $_term ) ) {
    			$clean_terms[] = (int) $_term[0];
    		} else {
    			// No existing term was found, so pass the string. A new term will be created.
    			$clean_terms[] = $term;
    		}
    	}

    	return $clean_terms;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-admin/includes/post.php#L2254)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-admin/includes/post.php#L2254-L2293)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/taxonomy_meta_box_sanitize_cb_input/?output_format=md#related)󠁿

| Uses | Description | 
| [get_terms()](https://developer.wordpress.org/reference/functions/get_terms/)`wp-includes/taxonomy.php` |

Retrieves the terms in a given taxonomy or list of taxonomies.

  | 
| [_x()](https://developer.wordpress.org/reference/functions/_x/)`wp-includes/l10n.php` |

Retrieves translated string with gettext context.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/taxonomy_meta_box_sanitize_cb_input/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.1.0](https://developer.wordpress.org/reference/since/5.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Ftaxonomy_meta_box_sanitize_cb_input%2F)
before being able to contribute a note or feedback.