getEntityRecord without knowing the post type

My question is, is there a similar selector for when you don’t know the post type of a post beforehand?

No, at the current time of writing there is not.

The fundamental problem is that the REST API doesn’t provide a generic mechanism for getting a post type given a post ID. You can retrieve a post and it will say post but to do this you need to know the type in advance to hit the correct URL.

Since the entity Record API relies on these endpoints, there technically are no post IDs. There’s a page record with an ID, or a post record with an ID, etc

So if you want to do this properly, you need to either save the post type, restrict the types allowed for that meta field, or loop through the different entity types to see which ones return a 404 and which one doesn’t.

Leave a Comment