In my plugin settings I got the custom post type set in variable $clientlogocptname

$clientlogocptname = get_option( 'clientlogocpt-select' );

How do I retrive the value of $clientlogocptname setting and pass it in getEntityRecords in "custompost_type" gutenberg block?? Is it possible to get the value in the block or can you suggest a better way?

const data = useSelect((select) => {
return select('core').getEntityRecords('postType', 'custompost_type');

2 Answers 2


As far as I can tell from looking into block editor store (you can use Redux devtools plugin for browser for that), entity for reading options is not registered. That means you cannot use getEntityRecord selector, which is usual way to obtain such data. Instead, either you can:

  1. Use apiFetch to fetch data from designated REST endpoint.
  2. Register your own entity to REST endpoint from 1. with addEntities and use getEntityRecord for getting data from option.

It looks like you're trying to retrieve the value of the clientlogocpt-select setting and use it as the value for the postType parameter in the getEntityRecords method. To do this, you can simply use the value of the $clientlogocptname variable as the value for the postType parameter like this:

const data = useSelect((select) => {
  return select('core').getEntityRecords('postType', $clientlogocptname);

This will retrieve the entity records for the custom post type specified by the clientlogocpt-select setting.

  • The block is coded in react. I will try your suggestion. Will let you know. Dec 10, 2022 at 10:04
  • $clientlogocptname didnt work. Dec 11, 2022 at 11:49
  • The answer is not correct. It mixes PHP which JS, which is not possible in the way answer was written. Answer should provide information how to retrieve option value via block editor selectors and it did not.
    – Lovor
    Dec 16, 2022 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.