wp_create_term

函式
wp_create_term ( $tag_name, $taxonomy = 'post_tag' )
引數
  • (string) $tag_name The term name.
    Required:
  • (string) $taxonomy Optional. The taxonomy within which to create the term. Default 'post_tag'.
    Required:
    Default: 'post_tag'
返回值
  • (array|WP_Error)
定義位置
相關方法
wp_create_userwp_create_categorywp_create_tagwpmu_create_userwp_delete_term
引入
2.8.0
棄用
-

wp_create_term: 這是一個在特定的分類法中建立一個新術語的函式。它可以用來以程式設計方式建立一個術語,而不是在WordPress儀表盤上手動建立。

在資料庫中新增一個新術語,如果它還不存在的話。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_create_term( $tag_name, $taxonomy = 'post_tag' ) {
$id = term_exists( $tag_name, $taxonomy );
if ( $id ) {
return $id;
}
return wp_insert_term( $tag_name, $taxonomy );
}
function wp_create_term( $tag_name, $taxonomy = 'post_tag' ) { $id = term_exists( $tag_name, $taxonomy ); if ( $id ) { return $id; } return wp_insert_term( $tag_name, $taxonomy ); }
function wp_create_term( $tag_name, $taxonomy = 'post_tag' ) {
	$id = term_exists( $tag_name, $taxonomy );
	if ( $id ) {
		return $id;
	}

	return wp_insert_term( $tag_name, $taxonomy );
}

常見問題

FAQs
檢視更多 >