函数文档

wp_get_split_term()

💡 云策文档标注

概述

wp_get_split_term() 函数用于获取与先前已分割的术语对应的新术语 ID。它基于旧术语 ID 和分类法参数,返回新术语 ID 或 false。

关键要点

  • 参数:$old_term_id(整数,必需,旧术语 ID)和 $taxonomy(字符串,必需,分类法)。
  • 返回值:整数(新术语 ID)或 false(如果未找到匹配的分割术语)。
  • 内部调用 wp_get_split_terms() 来获取分割术语数据。
  • 自 WordPress 4.2.0 版本引入。

代码示例

function wp_get_split_term( $old_term_id, $taxonomy ) {
    $split_terms = wp_get_split_terms( $old_term_id );

    $term_id = false;
    if ( isset( $split_terms[ $taxonomy ] ) ) {
        $term_id = (int) $split_terms[ $taxonomy ];
    }

    return $term_id;
}

📄 原文内容

Gets the new term ID corresponding to a previously split term.

Parameters

$old_term_idintrequired
Term ID. This is the old, pre-split term ID.
$taxonomystringrequired
Taxonomy that the term belongs to.

Return

int|false If a previously split term is found corresponding to the old term_id and taxonomy, the new term_id will be returned. If no previously split term is found matching the parameters, returns false.

Source

function wp_get_split_term( $old_term_id, $taxonomy ) {
	$split_terms = wp_get_split_terms( $old_term_id );

	$term_id = false;
	if ( isset( $split_terms[ $taxonomy ] ) ) {
		$term_id = (int) $split_terms[ $taxonomy ];
	}

	return $term_id;
}

Changelog

Version Description
4.2.0 Introduced.