get_cat_ID()
get_cat_ID( string $cat_name ) 从类别名称中检索该类别的ID。Retrieve …
get_cat_ID( string $cat_name )
从类别名称中检索该类别的ID。
Retrieve the ID of a category from its name.
目录锚点:#参数#返回#源码#笔记
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $cat_name | (string) | 必需 | 类别名称。 |
返回(Return)
(int)0,如果失败,则返回成功时的类别ID。
源码(Source)
/**
* Retrieve the ID of a category from its name.
*
* @since 1.0.0
*
* @param string $cat_name Category name.
* @return int 0, if failure and ID of category on success.
*/
function get_cat_ID( $cat_name ) {
$cat = get_term_by( 'name', $cat_name, 'category' );
if ( $cat )
return $cat->term_id;
return 0;
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 1.0.0 | wp-includes/category.php:195 | 2 | 1 function |
笔记(Notes)
例子:
对于需要类别ID的函数(如category_description())很有用:
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!