category_exists

函式
category_exists ( $cat_name, $category_parent = null )
引數
  • (int|string) $cat_name Category name.
    Required:
  • (int) $category_parent Optional. ID of parent category.
    Required:
    Default: null
返回值
  • (string|null) Returns the category ID as a numeric string if the pairing exists, null if not.
相關
  • term_exists()
定義位置
相關方法
term_existstag_existswp_category_checklistthe_category_rsscategory_description
引入
2.0.0
棄用
-

category_exists: 這個函式用來檢查一個類別是否存在。它接受一個單一的引數,即類別ID或slug。它返回一個布林值,表明該類別是否存在。

檢查一個類別是否存在。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function category_exists( $cat_name, $category_parent = null ) {
$id = term_exists( $cat_name, 'category', $category_parent );
if ( is_array( $id ) ) {
$id = $id['term_id'];
}
return $id;
}
function category_exists( $cat_name, $category_parent = null ) { $id = term_exists( $cat_name, 'category', $category_parent ); if ( is_array( $id ) ) { $id = $id['term_id']; } return $id; }
function category_exists( $cat_name, $category_parent = null ) {
	$id = term_exists( $cat_name, 'category', $category_parent );
	if ( is_array( $id ) ) {
		$id = $id['term_id'];
	}
	return $id;
}

常見問題

FAQs
檢視更多 >