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

返回介绍

get_cat_ID()

发布于 2017-09-10 字数2027 浏览 899 评论 0

get_cat_ID( string $cat_name )

Retrieve the ID of a category from its name.


描述


参数

$cat_name

(string)
(Required)
Category name.


返回值

(int) 0, if failure and ID of category on success.


源代码

File: wp-includes/category.php

function get_cat_ID( $cat_name ) {
	$cat = get_term_by( 'name', $cat_name, 'category' );
	if ( $cat )
		return $cat->term_id;
	return 0;
}

更新日志

Version 描述
1.0.0 Introduced.

相关函数

Uses

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

Used By

  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::mw_editPost()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::mw_newPost()

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 hearvox

    Example:

    <?php $cat_id = get_cat_ID ( 'Category Name' ); ?>
  2. Useful for a function such as category_描述() that requires a category’s ID:

    
    <?php $cat_id = get_cat_ID ( 'Category Name', 'textdomain' ); ?>
    <p>The 'Category Name' 描述 is: <?php echo category_描述( $cat_id ) ?></p>
    

上一篇:get_catname()

下一篇:get_cat_name()

发布评论

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

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