Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for some dynamically generated selectors in the core-data store #64269

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading