描述:
通过分类别名获取分类所有信息
用法:
<?php get_category_by_slug( $slug ); ?>
参数:
$slug
(string) (必填) 分类别名
默认值: None
示例:
<?php
$idObj = get_category_by_slug('category-slug');
$id = $idObj->term_id;
?>
演示代码:
/**
* Retrieve category object by category slug.
*
* @since 2.3.0
*
* @param string $slug The category slug.
* @return object Category data object
*/
function get_category_by_slug( $slug ) {
$category = get_term_by( 'slug', $slug, 'category' );
if ( $category )
_make_cat_compat( $category );
return $category;
}
发表评论
还没有评论,快来抢沙发吧!