rest_get_route_for_taxonomy_items

函式
rest_get_route_for_taxonomy_items ( $taxonomy )
引數
  • (string) $taxonomy Name of taxonomy.
    Required:
返回值
  • (string) The route path with a leading slash for the given taxonomy.
定義位置
相關方法
rest_get_route_for_post_type_itemsrest_get_route_for_termrest_get_route_for_postget_the_taxonomiesget_post_taxonomies
引入
5.9.0
棄用
-

rest_get_route_for_taxonomy_items: 這個函式用於檢索特定分類法的所有術語的REST API路由。它接受一個引數,即分類法名稱,並返回一個字串,代表指定分類法的所有術語的REST API路由。

獲取一個分類法的REST API路由。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function rest_get_route_for_taxonomy_items( $taxonomy ) {
$taxonomy = get_taxonomy( $taxonomy );
if ( ! $taxonomy ) {
return '';
}
if ( ! $taxonomy->show_in_rest ) {
return '';
}
$namespace = ! empty( $taxonomy->rest_namespace ) ? $taxonomy->rest_namespace : 'wp/v2';
$rest_base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
$route = sprintf( '/%s/%s', $namespace, $rest_base );
/**
* Filters the REST API route for a taxonomy.
*
* @since 5.9.0
*
* @param string $route The route path.
* @param WP_Taxonomy $taxonomy The taxonomy object.
*/
return apply_filters( 'rest_route_for_taxonomy_items', $route, $taxonomy );
}
function rest_get_route_for_taxonomy_items( $taxonomy ) { $taxonomy = get_taxonomy( $taxonomy ); if ( ! $taxonomy ) { return ''; } if ( ! $taxonomy->show_in_rest ) { return ''; } $namespace = ! empty( $taxonomy->rest_namespace ) ? $taxonomy->rest_namespace : 'wp/v2'; $rest_base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; $route = sprintf( '/%s/%s', $namespace, $rest_base ); /** * Filters the REST API route for a taxonomy. * * @since 5.9.0 * * @param string $route The route path. * @param WP_Taxonomy $taxonomy The taxonomy object. */ return apply_filters( 'rest_route_for_taxonomy_items', $route, $taxonomy ); }
function rest_get_route_for_taxonomy_items( $taxonomy ) {
	$taxonomy = get_taxonomy( $taxonomy );
	if ( ! $taxonomy ) {
		return '';
	}

	if ( ! $taxonomy->show_in_rest ) {
		return '';
	}

	$namespace = ! empty( $taxonomy->rest_namespace ) ? $taxonomy->rest_namespace : 'wp/v2';
	$rest_base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
	$route     = sprintf( '/%s/%s', $namespace, $rest_base );

	/**
	 * Filters the REST API route for a taxonomy.
	 *
	 * @since 5.9.0
	 *
	 * @param string      $route    The route path.
	 * @param WP_Taxonomy $taxonomy The taxonomy object.
	 */
	return apply_filters( 'rest_route_for_taxonomy_items', $route, $taxonomy );
}

常見問題

FAQs
檢視更多 >