What are all the query parameters for getEntityRecords?

I’m working on a plugin that defined a custom block for the Gutenberg/Block Editor. The block shows a select box of posts. When you select one, I create HTML with some of the selected post’s fields, such as title, date, etc.

When I query my posts in the edit method, my code correctly produces a list of pages (in my case, a custom post type named product), but custom fields, which this post type has, are not included.

var pages = select('core').getEntityRecords('postType', 'product', { per_page: -1 });

I’m trying to find documentation on getEntityRecords query parameters, but there seems to be none. Is it possible to include custom fields in the query? You would think this should be explained on https://wordpress.org/gutenberg/handbook/designers-developers/developers/data/data-core/#getentityrecords

My only other idea was: when the block is saved (“during” the save method), is it possible to do another query that just selects the single post by ID and retrieves its data, maybe including custom fields? It seems I can’t query anything during save.

2 s
2

If you look into the source code for getEntityRecords, you’ll see that the the core/data library creates entities using the WordPress API in entities.js.

So you can use any parameter available in the REST API. Here are options for posts:

context
page
per_page
search
after
author
author_exclude
before
exclude
include
offset
order
orderby
slug
status
categories
categories_exclude
tags
tags_exclude
sticky

Leave a Comment