Astra_Breadcrumb_Trail::add_term_parents( int $term_id, string $taxonomy )
Searches for term parents of hierarchical taxonomies. This function is similar to the WordPress function get_category_parents() but handles any type of taxonomy.
Description
Parameters
- $term_id
-
(int) (Required) ID of the term to get the parents of.
- $taxonomy
-
(string) (Required) Name of the taxonomy for the given term.
Return
(void)
Source
File: inc/addons/breadcrumbs/class-astra-breadcrumb-trail.php
function add_term_parents( $term_id, $taxonomy ) { // Set up some default arrays. $parents = array(); // While there is a parent ID, add the parent term link to the $parents array. while ( $term_id ) { // Get the parent term. $term = get_term( $term_id, $taxonomy ); // Add the formatted term link to the array of parent terms. $parents[] = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $term, $taxonomy ) ), $term->name ); // Set the parent term's parent as the parent ID. $term_id = $term->parent; } // If we have parent terms, reverse the array to put them in the proper order for the trail. if ( ! empty( $parents ) ) { $this->items = array_merge( $this->items, array_reverse( $parents ) ); } }
Expand full source code Collapse full source code View on Trac
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |