rest_get_route_for_post

函数
rest_get_route_for_post ( $post )
参数
  • (int|WP_Post) $post Post ID or post object.
    Required:
返回值
  • (string) The route path with a leading slash for the given post, or an empty string if there is not a route.
定义位置
相关方法
rest_get_route_for_termrest_get_route_for_post_type_itemsrest_get_route_for_taxonomy_items_reset_front_page_settings_for_postget_the_author_posts
引入
5.5.0
弃用
-

rest_get_route_for_post: 这个函数是用来检索特定文章的REST API路由的。它接受一个参数,即文章的ID,并返回一个代表指定文章的REST API路由的字符串。

获取一个文章的REST API路由。

function rest_get_route_for_post( $post ) {
	$post = get_post( $post );

	if ( ! $post instanceof WP_Post ) {
		return '';
	}

	$post_type_route = rest_get_route_for_post_type_items( $post->post_type );
	if ( ! $post_type_route ) {
		return '';
	}

	$route = sprintf( '%s/%d', $post_type_route, $post->ID );

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

常见问题

FAQs
查看更多 >