啊,我找到了。我只需要为每个术语指定一个唯一的名称(因此对于外部URL,我将它们命名为url-[md5]
哪里[md5]
是URL的MD5哈希),然后调用add_term_meta
并设置必要的信息,然后使用我的自定义分类法将此术语添加到帖子中。例如,这是正在工作的外部术语元数据设置器:
foreach ( $external_urls as $url ) {
$url = esc_url( $url );
// don\'t use wp_hash here because it salts the data
$term_name = "url-" . md5( $url );
$terms[$term_name] = $url;
}
// update post\'s reference taxonomy terms (replaces any existing terms)
wp_set_post_terms( $post->ID, array_keys( $terms ), \'external_reference\' );
// add metadata
foreach ( $terms as $term_name => $url ) {
// get term
$term = get_term_by( \'name\', $term_name, \'external_reference\' );
// add URL as metadata for the term created above
update_term_meta( $term->term_id, "url", $url );
}