get_term()通过分类的信息

目录

描述

Get all Term data from database by Term ID. To retrieve term data by name, slug or ID, use get_term_by() instead

The usage of the get_term function is to apply filters to a term object. It is possible to get a term object from the database before applying the filters.

$term ID must be part of $taxonomy, to get from the database. Failure, might be able to be captured by the hooks. Failure would be the same value as $wpdb returns for the get_row method.

There are two hooks, one is specifically for each term, named 'get_term', and the second is for the taxonomy name, 'term_$taxonomy'. Both hooks gets the term object, and the taxonomy name as parameters. Both hooks are expected to return a Term object.

'get_term' hook - Takes two parameters the term Object and the taxonomy name. Must return term object. Used in get_term() as a catch-all filter for every $term.

'get_$taxonomy' hook - Takes two parameters the term Object and the taxonomy name. Must return term object. $taxonomy will be the taxonomy name, so for example, if 'category', it would be 'get_category' as the filter name. Useful for custom taxonomies or plugging into default taxonomies.

get_term() 描述

用法

<?php get_term$term$taxonomy$output$filter ?>

get_term() 用法

参数

$term

(integer|object) (必填) If integer, will get from database. If object will apply filters and return $term.

默认值: None

$taxonomy

(string) (必填) Taxonomy name that $term is part of.

默认值: None

$output

(string) (可选) Constant OBJECT, ARRAY_A, or ARRAY_N

默认值: OBJECT

$filter

(string) (可选) default is raw or no WordPress defined filter will applied.

默认值: 'raw'

get_term() 参数

返回值

(mixed|null|WP_Error) 

Term Row from database. Will return null if $term is empty. If taxonomy does not exist then WP_Error will be returned.

get_term() 返回值

示例

Get Term offers some handy information, but unfortunately lacks a link value.

$term = get_term( $term_id, $taxonomy );

Gives you term slug: e.g.: term-slug-example

$slug = $term->slug;

Gives you term name: e.g. Term Name Example

$name = $term->name;

Gives you term description: e.g. This is my new cool custom term.

$desc = $term->description;

get_term() 示例

注意

get_term() 注意

历史

添加于 版本: 2.3.0

get_term() 历史

源文件

&get_term() 函数的代码位于 wp-includes/taxonomy.php.

get_term() 源文件

相关