首页 WordPress函数大全 get_term()

get_term()

2020-05-01 / 3680阅 / 悠然

如何你看完本文还不知道如何使用该函数,可以联系我定制视频教程,50元/个函数,学不会全额退款

get_term( int|WP_Term|object $term, string $taxonomy = '', string $output = OBJECT, string $filter = 'raw' )

Get all Term data from database by Term ID.

描述

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,>‘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.

See also See also

  • sanitize_term_field(): The $context param lists the available values for get_term_by() $filter param.

Top ↑

参数

$term

(int|WP_Term|object)
(Required)
If integer, term data will be fetched from the database, or from the cache if available. If stdClass object (as in the results of a database query), will apply filters and return a WP_Term object corresponding to the $term data. If WP_Term, will return $term.

$taxonomy

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

Default value: ''

$output

(string)
(Optional)
The required return type.>WP_Term object, an associative array, or a numeric array, respectively.

Default value: OBJECT

$filter

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

Default value: 'raw'

返回

(WP_Term|array|WP_Error|null) Object of the type specified by $output>WP_Term instance is returned. If taxonomy does not exist, a WP_Error is returned. Returns null for miscellaneous failure.

大家谈论
    我的见解