wp_term_is_shared()WP 4.4.0

Determine whether a term is shared between multiple taxonomies.

Shared taxonomy terms began to be split in 4.3, but failed cron tasks or other delays in upgrade routines may cause shared terms to remain.

No Hooks.

Return

true|false. Returns false if a term is not shared between multiple taxonomies or if splitting shared taxonomy terms is finished.

Usage

wp_term_is_shared( $term_id );
$term_id(int) (required)
Term ID.

Examples

0

#1 Check whether the term 123 is generic

$term_id = 123;

if( wp_term_is_shared( $term_id ) ){
	echo "{$term_id} is a generic term";
}

Notes

  • Global. wpdb. $wpdb WordPress database abstraction object.

Changelog

Since 4.4.0 Introduced.

wp_term_is_shared() code WP 6.5.2

function wp_term_is_shared( $term_id ) {
	global $wpdb;

	if ( get_option( 'finished_splitting_shared_terms' ) ) {
		return false;
	}

	$tt_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id ) );

	return $tt_count > 1;
}