最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

block editor - What is the significance of 'root' in getEntityRecords?

programmeradmin2浏览0评论

I've gone through the documentation and the source code but I couldn't understand.

I have 2 queries:

getEntityRecords( 'postType', 'post' ); and getEntityRecords( 'root', 'user' ).

  1. Why does the 2nd query require root as the 1st argument?
  2. What does it mean?
  3. How to determine when to use it?

The doc describes the parameters of getEntityRecords as following:

Parameters:

  • state Object: State tree
  • kind string: Entity kind.
  • name string: Entity name.
  • query ?Object: Optional terms query.
  1. Are postType and root both state trees?
  2. How does state relate to kind while referring to entities.js?

I've gone through the documentation and the source code but I couldn't understand.

I have 2 queries:

getEntityRecords( 'postType', 'post' ); and getEntityRecords( 'root', 'user' ).

  1. Why does the 2nd query require root as the 1st argument?
  2. What does it mean?
  3. How to determine when to use it?

The doc describes the parameters of getEntityRecords as following:

Parameters:

  • state Object: State tree
  • kind string: Entity kind.
  • name string: Entity name.
  • query ?Object: Optional terms query.
  1. Are postType and root both state trees?
  2. How does state relate to kind while referring to entities.js?
Share Improve this question asked Feb 26, 2022 at 21:06 Siddharth ThevarilSiddharth Thevaril 5676 silver badges22 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

The important thing to note is that post is a kind/sub-type of the post types entity, all posts regardless of type share the same table and general data structure and fields etc.

This contrasts with other major entity types such as comments or users.

However, what if there is no kind or sub-type? What if your entity is a user? What would you put as the entity kind/sub-type? There is only 1 kind of user! So you go one level up, and that's where root comes from.

It's also useful to know that entities are very related to the REST API and endpoints, and that this is the only connection to the PHP side of things. Entities only exist in the WP javascript packages. It's possible to use the REST API and javascript without referring to entities on the frontend, but if you're working with the block editor it's highly relevant.

发布评论

评论列表(0)

  1. 暂无评论