rest_get_route_for_term() WordPress Function

The rest_get_route_for_term() function is used to get the REST route for a given term. This function is useful for customizing the output of your REST API requests.

rest_get_route_for_term( int|WP_Term $term ) #

Gets the REST API route for a term.


Parameters

$term

(int|WP_Term)(Required)Term ID or term object.


Top ↑

Return

(string) The route path with a leading slash for the given term, or an empty string if there is not a route.


Top ↑

Source

File: wp-includes/rest-api.php

function rest_get_route_for_term( $term ) {
	$term = get_term( $term );

	if ( ! $term instanceof WP_Term ) {
		return '';
	}

	$taxonomy_route = rest_get_route_for_taxonomy_items( $term->taxonomy );
	if ( ! $taxonomy_route ) {
		return '';
	}

	$route = sprintf( '%s/%d', $taxonomy_route, $term->term_id );

	/**
	 * Filters the REST API route for a term.
	 *
	 * @since 5.5.0
	 *
	 * @param string  $route The route path.
	 * @param WP_Term $term  The term object.
	 */
	return apply_filters( 'rest_route_for_term', $route, $term );
}


Top ↑

Changelog

Changelog
VersionDescription
5.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More