Astra_Breadcrumb_Trail::add_post_terms( int $post_id, string $taxonomy )

Adds a post’s terms from a specific taxonomy to the items array.


Description


Parameters

$post_id

(int) (Required) The ID of the post to get the terms for.

$taxonomy

(string) (Required) The taxonomy to get the terms from.


Return

(void)


Source

File: inc/addons/breadcrumbs/class-astra-breadcrumb-trail.php

	protected function add_post_terms( $post_id, $taxonomy ) {


		// Get the post categories.
		$terms = get_the_terms( $post_id, $taxonomy );

		// Check that categories were returned.
		if ( $terms && ! is_wp_error( $terms ) ) {

			// Sort the terms by ID and get the first category.
			if ( function_exists( 'wp_list_sort' ) ) {
				$terms = wp_list_sort( $terms, 'term_id' );
			}
			else {
				usort( $terms, '_usort_terms_by_ID' );
			}
			$term = get_term( $terms[0], $taxonomy );

			// If the category has a parent, add the hierarchy to the trail.
			if ( 0 < $term->parent ) {
				$this->add_term_parents( $term->parent, $taxonomy );
			}
			// Add the category archive link to the trail.
			$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $term, $taxonomy ) ), $term->name );
		}
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.