首页 WordPress函数大全 get_term_by()

get_term_by()

2020-05-01 / 5825阅 / 悠然

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

get_term_by( string $field, string|int $value, string $taxonomy = '', string $output = OBJECT, string $filter = 'raw' )

Get all Term data from database by Term field and data.

描述

Warning: $value is not escaped for ‘name’ $field. You must do it yourself, if required.

The default $field is ‘id’, therefore it is possible to also use null for field, but not recommended that you do so.

If $value does not exist, the return value will be false. If $taxonomy exists and $field and $value combinations exist, the Term will be returned.

This function will always return the first term that matches the $field– $value–$taxonomy combination specified in the parameters. If your query is likely to match more than>get_terms() instead; that way, you will get all matching terms, and can provide your own logic for deciding which id="see-also" tabindex="-1">See also See also

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

Top ↑

参数

$field

(string)
(Required)
Either 'slug', 'name', 'id' (term_id), or 'term_taxonomy_id'

$value

(string|int)
(Required)
Search for this term value

$taxonomy

(string)
(Optional)
Taxonomy name. Optional, if $field is 'term_taxonomy_id'.

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|false) WP_Term instance (or array) on success. Will return false if $taxonomy does not exist or $term was not found.

大家谈论
    我的见解