Skip to content

Commit

Permalink
Add docs for some dynamically generated selectors in the core-data st…
Browse files Browse the repository at this point in the history
…ore (#64269)

* Add post type and taxonomy selectors.

* Run docs build

* Change order to fix heading issue.

Co-authored-by: ryanwelcher <welcher@git.wordpress.org>
Co-authored-by: justintadlock <greenshady@git.wordpress.org>
  • Loading branch information
3 people authored Aug 5, 2024
1 parent 650eb7f commit 6078a01
Showing 1 changed file with 100 additions and 1 deletion.
101 changes: 100 additions & 1 deletion docs/reference-guides/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,106 @@

Namespace: `core`.

## Selectors
### Dynamically generated selectors

There are a number of user-friendly selectors that are wrappers of the more generic `getEntityRecord` and `getEntityRecords` that can be used to retrieve information for the various entities.

### getPostType

Returns the information for a given post type.

_Usage_

import { useSelect } from '@wordpress/data';
import { store as coreDataStore } from '@wordpress/core-data';

const postType = useSelect(
( select ) => select( coreDataStore ).getPostType( 'post' )

// Equivalent to: select( coreDataStore ).getEntityRecord( 'root', 'postType', 'post' )
);

_Parameters_

- postType `string`

_Returns_

- `EntityRecord | undefined`: Record.

### getPostTypes

Returns the information for post types.

_Usage_

import { useSelect } from '@wordpress/data';
import { store as coreDataStore } from '@wordpress/core-data';

const postTypes = useSelect( ( select ) => {
return select( coreDataStore ).getPostTypes( { per_page: 4 } );

// Equivalent to:
// select( coreDataStore ).getEntityRecords( 'root', 'postType', { per_page: 4 } );
} );

_Parameters_

- _query_ `GetRecordsHttpQuery`: Optional terms query. If requesting specific fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".

_Returns_

- `EntityRecord[] | null`: Records.

### getTaxonomy

Returns information for a given taxonomy.

_Usage_

import { useSelect } from '@wordpress/data';
import { store as coreDataStore } from '@wordpress/core-data';

const taxonomy = useSelect( ( select ) => {
return select( coreDataStore ).getTaxonomy( 'category' );

// Equivalent to:
// select( coreDataStore ).getEntityRecord( 'root', 'taxonomy', 'category' );
} );

_Parameters_

- taxonomy `string`

_Returns_

- `EntityRecord | undefined`: Record.

### getTaxonomies

Returns information for taxonomies.

_Usage_

import { useSelect } from '@wordpress/data';
import { store as coreDataStore } from '@wordpress/core-data';

const taxonomies = useSelect( ( select ) => {
return select( coreDataStore ).getTaxonomies( { type: 'post' } );

// Equivalent to:
// select( coreDataStore ).getEntityRecords( 'root', 'taxonomy', { type: 'post' } );
} );

_Parameters_

- _query_ `GetRecordsHttpQuery`: Optional terms query. If requesting specific fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".

_Returns_

- `EntityRecord[] | null`: Records.

## Other Selectors

<!-- START TOKEN(Autogenerated selectors|../../../packages/core-data/src/selectors.ts) -->

Expand Down

0 comments on commit 6078a01

Please sign in to comment.