wp_insert_term_duplicate_term_check
Filter HookDescription
Filters the duplicate term check that takes place during term creation. Term parent + taxonomy + slug combinations are meant to be unique, and wp_insert_term() performs a last-minute confirmation of this uniqueness before allowing a new term to be created. Plugins with different uniqueness requirements may use this filter to bypass or modify the duplicate-term check.Hook Information
File Location |
wp-includes/taxonomy.php
View on GitHub
|
Hook Type | Filter |
Line Number | 2641 |
Hook Parameters
Type | Name | Description |
---|---|---|
object
|
$duplicate_term
|
Duplicate term row from terms table, if found. |
string
|
$term
|
Term being inserted. |
string
|
$taxonomy
|
Taxonomy name. |
array
|
$args
|
Arguments passed to wp_insert_term(). |
int
|
$tt_id
|
term_taxonomy_id for the newly created term. |
Usage Examples
Basic Usage
<?php
// Hook into wp_insert_term_duplicate_term_check
add_filter('wp_insert_term_duplicate_term_check', 'my_custom_filter', 10, 5);
function my_custom_filter($duplicate_term, $term, $taxonomy, $args, $tt_id) {
// Your custom filtering logic here
return $duplicate_term;
}
Source Code Context
wp-includes/taxonomy.php:2641
- How this hook is used in WordPress core
<?php
2636 * @param string $term Term being inserted.
2637 * @param string $taxonomy Taxonomy name.
2638 * @param array $args Arguments passed to wp_insert_term().
2639 * @param int $tt_id term_taxonomy_id for the newly created term.
2640 */
2641 $duplicate_term = apply_filters( 'wp_insert_term_duplicate_term_check', $duplicate_term, $term, $taxonomy, $args, $tt_id );
2642
2643 if ( $duplicate_term ) {
2644 $wpdb->delete( $wpdb->terms, array( 'term_id' => $term_id ) );
2645 $wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $tt_id ) );
2646
PHP Documentation
<?php
/**
* Filters the duplicate term check that takes place during term creation.
*
* Term parent + taxonomy + slug combinations are meant to be unique, and wp_insert_term()
* performs a last-minute confirmation of this uniqueness before allowing a new term
* to be created. Plugins with different uniqueness requirements may use this filter
* to bypass or modify the duplicate-term check.
*
* @since 5.1.0
*
* @param object $duplicate_term Duplicate term row from terms table, if found.
* @param string $term Term being inserted.
* @param string $taxonomy Taxonomy name.
* @param array $args Arguments passed to wp_insert_term().
* @param int $tt_id term_taxonomy_id for the newly created term.
*/
Quick Info
- Hook Type: Filter
- Parameters: 5
- File: wp-includes/taxonomy.php
Related Hooks
Related hooks will be displayed here in future updates.