diff --git a/packages/wp-types/readme.md b/packages/wp-types/readme.md index 7321812..6cd0ce1 100644 --- a/packages/wp-types/readme.md +++ b/packages/wp-types/readme.md @@ -241,6 +241,28 @@ api.catch( ( error: WP_REST_API_Error ) => { } ); ``` +Usage with entity records: + +```ts +import type { + WP_REST_API_Posts, + WP_REST_API_Term, +} from 'wp-types'; + +const category = getEntityRecord( + 'taxonomy', + 'category', + id, +); + +const posts = getEntityRecords( + 'postType', + 'post', + query +); +const taxonomy = getEntityRecord('taxonomy', taxonomy, term); +``` + ## FAQs ### When do these definitions apply? @@ -254,7 +276,7 @@ printf( ); ``` -The REST API object schemas apply to the response to a REST API request. For example: +The REST API object schemas apply to the response to a REST API request or entity record request. Examples: ```js const api = wp.apiFetch( { @@ -262,6 +284,20 @@ const api = wp.apiFetch( { } ); ``` +```js +const category = getEntityRecord( + 'taxonomy', + 'category', + id, +); + +const posts = getEntityRecords( + 'postType', + 'post', + query +); +``` + The definitions also apply outside of the browser, for example if you're saving data as JSON and reading it in a Node application. ### How do I know these definitions are valid? diff --git a/readme.md b/readme.md index 2c8217a..d86bdae 100644 --- a/readme.md +++ b/readme.md @@ -215,7 +215,7 @@ printf( ); ``` -The REST API object schemas apply to the response to a REST API request. For example: +The REST API object schemas apply to the response to a REST API request or `getEntityRecord()` call. Examples: ```js const api = wp.apiFetch( { @@ -223,6 +223,20 @@ const api = wp.apiFetch( { } ); ``` +```js +const category = getEntityRecord( + 'taxonomy', + 'category', + id, +); + +const posts = getEntityRecords( + 'postType', + 'post', + query +); +``` + The schemas also apply outside of an HTTP request, for example if you're saving data as a JSON file and reading it in a Node application. ### Why are there different schemas for PHP objects and REST API responses?