get_term_parents_list

Advertisement

Summery Summery

Retrieve term parents with separator.

Syntax Syntax

get_term_parents_list( int $term_id, string $taxonomy, string|array $args = array() )

Parameters Parameters

$term_id

(Required) Term ID.

$taxonomy

(Required) Taxonomy name.

$args

(Optional) Array of optional arguments.

  • 'format'
    (string) Use term names or slugs for display. Accepts 'name' or 'slug'. Default 'name'.
  • 'separator'
    (string) Separator for between the terms. Default '/'.
  • 'link'
    (bool) Whether to format as a link. Default true.
  • 'inclusive'
    (bool) Include the term to get the parents for. Default true.

Default value: array()

Return Return

(string|WP_Error) A list of term parents on success, WP_Error or empty string on failure.

Source Source

File: wp-includes/category-template.php

	if ( empty( $terms ) ) {
		return false;
	}

	$links = array();

	foreach ( $terms as $term ) {
		$link = get_term_link( $term, $taxonomy );
		if ( is_wp_error( $link ) ) {
			return $link;
		}
		$links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
	}

	/**
	 * Filters the term links for a given taxonomy.
	 *
	 * The dynamic portion of the filter name, `$taxonomy`, refers
	 * to the taxonomy slug.
	 *
	 * @since 2.5.0
	 *
	 * @param string[] $links An array of term links.
	 */
	$term_links = apply_filters( "term_links-{$taxonomy}", $links );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores

	return $before . join( $sep, $term_links ) . $after;
}

/**
 * Retrieves term parents with separator.
 *
 * @since 4.8.0
 *
 * @param int          $term_id  Term ID.
 * @param string       $taxonomy Taxonomy name.
 * @param string|array $args {
 *     Array of optional arguments.
 *
 *     @type string $format    Use term names or slugs for display. Accepts 'name' or 'slug'.
 *                             Default 'name'.
 *     @type string $separator Separator for between the terms. Default '/'.
 *     @type bool   $link      Whether to format as a link. Default true.
 *     @type bool   $inclusive Include the term to get the parents for. Default true.
 * }
 * @return string|WP_Error A list of term parents on success, WP_Error or empty string on failure.

Advertisement

Changelog Changelog

Changelog
Version Description
4.8.0 Introduced.

Advertisement

Leave a Reply