get_category_by_slug() - WordPress 函数参考中文文档

返回介绍

get_category_by_slug()

发布于 2017-09-10 字数1684 浏览 914 评论 0

get_category_by_slug( string $slug )

Retrieve category object by category slug.


描述


参数

$slug

(string)
(Required)
The category slug.


返回值

(object) Category data object


源代码

File: wp-includes/category.php

function get_category_by_slug( $slug  ) {
	$category = get_term_by( 'slug', $slug, 'category' );
	if ( $category )
		_make_cat_compat( $category );

	return $category;
}

更新日志

Version 描述
2.3.0 Introduced.

相关函数

Uses

  • wp-includes/category.php:
    _make_cat_compat()
  • wp-includes/taxonomy.php:
    get_term_by()

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

    Contributed by Ivan Shulev

    Returns false if not found

  2. Example

    
    $idObj = get_category_by_slug( 'category-slug' );
    
    if ( $idObj instanceof WP_Term ) {
    	$id = $idObj->term_id;
    }
    

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!