rest_get_route_for_term

函式
rest_get_route_for_term ( $term )
引數
  • (int|WP_Term) $term Term ID or term object.
    Required:
返回值
  • (string) The route path with a leading slash for the given term, or an empty string if there is not a route.
定義位置
相關方法
rest_get_route_for_postrest_get_route_for_post_type_itemsrest_get_route_for_taxonomy_itemsrest_get_best_type_for_valuerest_get_url_prefix
引入
5.5.0
棄用
-

rest_get_route_for_term: 這個函式用於檢索分類法中某個特定術語的REST API路由。它接受兩個引數,術語ID和分類法名稱,並返回一個代表指定術語的REST API路由的字串。

獲取一個術語的REST API路由。

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 );
}

常見問題

FAQs
檢視更多 >