Get Object Terms : Retrieves an array of WP_Term
object associated with the given post, in the supplied taxonomies.
Term object ( WP_Term
)offers some handy information. For example,
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;
But unfortunately lacks a link value. So use Get Term Link to generate a permalink for a taxonomy term archive.
$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,
),
),
);