-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Documentation: Document usage of core
entities (getEntityRecords
, etc)
#12120
Comments
I'm moving this out of @Novalis80 I found an article with several examples that use https://riad.blog/2018/06/07/efficient-client-data-management-for-wordpress-plugins/#comment-1077 |
Would love some more documentation on Entities in general. |
Responding to this specific request, you can achieve this by the following: wp.data.select( 'core' ).getEntityRecords( 'postType', 'post', { categories: [ /* ... */ ] } ) ...where the first two arguments correspond to retrieving entities of a particular post type (source) and the last is an object of query arguments to include in the request. Note that the first time it is called, it may return an empty result, since it needs to fetch the data from the REST API. You can subscribe to changes in state by either using I agree there should be better documentation here. |
core
entities (getEntityRecords
, etc)
#15200 is a first pass here, which will include formatted documentation in the |
@aduth This only works in the editor page. I am building a custom plugin with React that doesnt invlove gutenberg. I am trying to fetch latest posts , but in my Custom Plugin admin page, when I console log Is this restricted to only on editor pages? How do I use it for another custom page? Do I have to use the rest api? |
@towfiqi If you rely on data from a particular module, you must ensure that your script defines that module as a dependency, using the In your case, wp_enqueue_script( 'my-script', 'my-src.js', array( 'wp-core-data' ) ); All packages are registered in WordPress with the |
I was trying |
The documentation and event the source code says that getEntityRecords accepts four arguments, the first beeing a 'State Tree' object. But every example I see just uses three arguments, like this: |
I am late for an answer, but as I understood from reading, useSelect or withSelect inject first argument, i.e. state |
For anyone else still trying to figure this out and what are some basic questions (what is an entity? what are entityrecords? ) #37615 answers some of these questions; Here is the The most recent published version . |
It looks like this documentation does exist |
I read the docs for "getEntityRecords" and i have no clue what that is nor what is available:
So if anybody can shed some light on the issue i would be grateful.
My specific task is to get all posts of a certain category into a custom block. I guess this is the method that will get the job done?!
The text was updated successfully, but these errors were encountered: