Get Object Terms : 检索的数组WP_Term
在提供的分类法中,与给定帖子关联的对象。
Term object ( WP_Term
)offers some handy information. For example,
为您提供术语
slug
: e、 g.:
term-slug-example
$slug = $term->slug;
为您提供术语
name
: e、 g。
Term Name Example
$name = $term->name;
为您提供术语
description
: e、 g。
This is my new cool custom term
.
$desc = $term->description;
但不幸的是,缺少链接值。So使用
Get Term Link 为分类术语存档生成永久链接。
$term_link = get_term_link( $term);
So your finalcode should look like this:
$sub_cats = wp_get_object_terms( $post->ID, DocumentsTaxonomy::DOCUMENTS_TAXONOMY_KEY, ); // array of categories associated with current post
$args_docs = array(
\'post_type\' => Documents::DOCUMENTS_TYPE_KEY,
\'posts_per_page\' => -1,
\'tax_query\' => array(
array(
\'taxonomy\' => DocumentsTaxonomy::DOCUMENTS_TAXONOMY_KEY,
\'field\' => \'term_id\',
\'terms\' => $sub_cats[0]->parent,
),
),
);