wp_get_split_terms()WP 4.2.0

Get data about terms that previously shared a single term_id, but have since been split.

No Hooks.

Return

Array. Array of new term IDs, keyed by taxonomy.

Usage

wp_get_split_terms( $old_term_id );
$old_term_id(int) (required)
Term ID. This is the old, pre-split term ID.

Examples

0

#1 Fix taxonomy item IDs in the 'featured_tags' option after splitting

The recommended fixing method is the split_shared_term hook. However, when the plugin is updated after splitting, it is no longer possible to stick to this hook. In this case wp_get_split_terms(), which stores split information, will help.

Suppose the plugin stored term IDs in the featured_tags option. We need to make sure that none of the terms stored in featured_tags have been split, and if so, we need to update the IDs in that option.

function featured_tags_check_for_split_terms() {

	$featured_tag_ids = get_option( 'featured_tags', array() );

	// Check if there are ID terms from the taxonomy `post_tag` that have been separated
	foreach ( $featured_tag_ids as $index => $featured_tag_id ) {

		$split_terms = wp_get_split_terms( $featured_tag_id, 'post_tag' );

		if ( ! empty( $split_terms ) ) {
			foreach ( $split_terms as $split_term ) {
				// Replacing old IDs with new ones
				$featured_tag_ids[ $index ] = $split_term['post_tag'];
			}
		}
	}

	// Update
	update_option( 'featured_tags', $featured_tag_ids );
}
0

#2 Let's check if there is data about taxonomy elements separation on the site

To check if the taxonomy elements have been separated at all, run this code:

$split_terms = get_option( '_split_terms', [] );

if( $split_terms ){
	// разделение было и есть данные о разделении
}
else {
	// данных о разделении нет (но код разделения скорее всего сработал)
	// просто у вас не оказалось терминов с одинаковыми ИД
}
print_r( $split_terms );

/* displays:
Array
(
	[3] => Array
		(
			[post_tag] => 591
		)

	[18] => Array
		(
			[post_tag] => 592
		)
)
*/

If array() prints out the result, you did not have terms with the same ID after the split and the option can be removed without consequences:

delete_option( '_split_terms' );

Changelog

Since 4.2.0 Introduced.

wp_get_split_terms() code WP 6.5.2

function wp_get_split_terms( $old_term_id ) {
	$split_terms = get_option( '_split_terms', array() );

	$terms = array();
	if ( isset( $split_terms[ $old_term_id ] ) ) {
		$terms = $split_terms[ $old_term_id ];
	}

	return $terms;
}