wp_get_post_terms

函式
wp_get_post_terms ( $post_id = 0, $taxonomy = 'post_tag', $args = array() )
引數
  • (int) $post_id Optional. The Post ID. Does not default to the ID of the global $post. Default 0.
    Required:
  • (string|string[]) $taxonomy Optional. The taxonomy slug or array of slugs for which to retrieve terms. Default 'post_tag'.
    Required:
    Default: 'post_tag'
  • (array) $args { Optional. Term query parameters. See WP_Term_Query::__construct() for supported arguments. @type string $fields Term fields to retrieve. Default 'all'. }
    Required:
    Default: array()
返回值
  • (array|WP_Error) Array of WP_Term objects on success or empty array if no terms were found. WP_Error object if `$taxonomy` doesn't exist.
定義位置
相關方法
wp_set_post_termswp_get_split_termswp_get_post_catswp_get_post_tagswp_get_object_terms
引入
2.8.0
棄用
-

wp_get_post_terms: 這個函式用於檢索與特定文章相關的術語(類別、標籤等)。它把文章的ID和分類法作為引數,並返回一個術語物件的陣列,每個物件都包含有關術語的資訊。

檢索一個文章的術語。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array() ) {
$post_id = (int) $post_id;
$defaults = array( 'fields' => 'all' );
$args = wp_parse_args( $args, $defaults );
$tags = wp_get_object_terms( $post_id, $taxonomy, $args );
return $tags;
}
function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array() ) { $post_id = (int) $post_id; $defaults = array( 'fields' => 'all' ); $args = wp_parse_args( $args, $defaults ); $tags = wp_get_object_terms( $post_id, $taxonomy, $args ); return $tags; }
function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array() ) {
	$post_id = (int) $post_id;

	$defaults = array( 'fields' => 'all' );
	$args     = wp_parse_args( $args, $defaults );

	$tags = wp_get_object_terms( $post_id, $taxonomy, $args );

	return $tags;
}

常見問題

FAQs
檢視更多 >