I’m answering myself for the benefit of others. I was passing an array of post type slugs to apiFetch
instead of passing an array with their rest_base
parameter. So, the correct function should be:
const postTypes = useSelect( ( select ) => {
const { getPostTypes } = select( 'core' );
const excludedPostTypes = [ 'attachment' ];
const filteredPostTypes = getPostTypes( { per_page: -1 } )?.filter(
( { viewable, slug } ) => viewable && ! excludedPostTypes.includes( slug )
);
const result = ( filteredPostTypes || [] ).map( ( { rest_base } ) => rest_base );
return result;
}, [] );
Related Posts:
- Gutenberg custom block plugin with custom image sizes
- Get loading state of wp data selector
- var is undefined in a Gutenberg block
- How to transform a legacy widget into a block
- Get Block Attributes in JSON REST API
- Checks when fetching data from multiple REST API endpoints in Gutenberg
- Using apiFetch for retrieving post data in Gutenberg
- Get terms of a taxonomy using useSelect
- Update block once an API request returns with a value
- Trigger Javascript on Gutenberg (Block Editor) Save
- Nonce retrieved from the REST API is invalid and different from nonce generated in wp_localize_script
- Gutenberg – remove / add blocks with custom script
- How to use wp.hooks.addAction() in React JS/Gutenberg?
- REST API: Backbone and custom endpoint
- Show control conditionally in Gutenberg
- How to get the ToggleControl Gutenberg component working for a PHP Block
- Hooking a callback into the code within a Gutenberg block
- conditional layout based on if Innerblocks is not empty
- Gutenberg extend blocks add new class name
- initial open/toggle PluginDocumentSettingPanel panel in document setting block editor gutenberg
- WP REST – video and audio players
- Headless WordPress: How to authenticate front end requests?
- Post to WordPress using REST API from external site
- What do the args for Gutenberg subpackage “hooks” function “doAction” mean?
- How to handle malformed response from WP REST API?
- How do I fire a snackbar notice in admin?
- Rest API authentication issue when called from fetch request in bundle.js
- What is “open()” in MediaUpload?
- WordPress Rest API only returns content when posttype has editor capability
- Why is this gutenberg custom format button only available from the toolbar as a dropdown?
- Rest API invalid nonce with Backbone Client
- Provide specific example for block variation
- Use useSelect/useDispatch instead of withSelect/withDispatch
- How to handle Gutenberg wp.data async errors?
- Set current tab on a Gutenberg TabPanel component from outside that component
- Block editor: How to check if block editor has initialized and populated the data store?
- Load script after block is inserted
- Gutenberg block “This block appears to have been modified externally” on save
- How do I access site and block editor state data and use `useSelect()` or `withSelect()` to bind it to my components?
- Gutenberg passing block attributes to component in ES6/ESNext
- Can the index.asset.php file be used with the enqueue_block_editor_assets action?
- WP REST API Post Status Using JavaScript
- Gutenberg add extra attributes to custom format
- Using wp.data.select get actual tags (not id’s) used in post
- How to remove p / br elements from gutenbergs editor
- Script Localization doesn’t work
- Programatically update posts in database from one block to another using transform
- Gutenberg getMedia() in post query doesn’t return all featured images
- Gutenberg select categories
- Listening change event of taxonomy term checkboxes in Gutenberg editor
- Gutenberg get core data – search
- What is the correct way to import the blocks-editor?
- Gutenberg extend blocks add new class name
- How to add classes and events to image in javascript using Gutenberg?
- Add custom classes for blocks in editor based on custom attributes
- useSelect second parameter
- How can I allow HTML in Gutenberg UI elements help text?
- what is the purpose of the namespace argument when customizing blocks?
- Trigger wp-embed via JavaScript to refresh iframe preview?
- Gutenberg getBlockIndex in save() function
- Widgets and Post/Page edit/new blank, console errors only, no server errors
- Trying to turn the Edit function into a class to be able to use React lifecycle methods
- Gutenberg richtext block vaildation failed
- UnitControl – Block has encountered an error
- Conditional save return on Gutenberg Block
- Can I alter the block editor’s paste text behavior?
- Custom Gutenberg-Block esnext pass variables
- Building a Featured Gallery component for Gutenberg
- Gutenberg dependencies in package.json
- Return ‘X-WP-Total’ from headers in response
- How to render WP Rest-API Endpoints in a React.js Theme with Woocommerce
- How to read inline-CSS from Gutenberg block?
- Custom Block – save.js function not saving attributes
- Retrieving data about comments and likes
- Gutenberg – useEffect manipulate DOM after block re-renders DOM
- Problem extending a core block
- Cannot read properties of undefined (reading ‘show_ui’) Error on WordPress Post Editor
- Check if user can in javascript
- Why does my array sort order changes when I pass it to JS using WP_REST_Response?
- Rest API and how to deal with it in server side
- why is apiFetch throwing Unhandled Promise Rejection: TypeError: Object is not a function
- Access checks with custom REST endpoints and backbone
- Issue migrating a checkbox-type meta field to the block editor
- Gutenberg – dynamically created element: how to set onChange?
- Custom block update rendering when reused
- WordPress Gutenberg Ajax request
- WP Gutenberg – custom block with two content fields
- Gutenberg Edit Block Inspector Controls and save
- Spans in gutenberg
- Block pattern conflict with custom block
- Table block variation with header section activated
- WordPress REST API response is empty in browser and script, but not in Postman
- Where to include JS library in gutenberg blocks
- WP REST API – “rest_user_cannot_view” ONLY on specific users
- Passing object to FormTokenField suggestions
- Is it possible to add javascript to template parts
- How to add a new attribute to core wp block editor without npm?
- How do i get an Inline style in Gutenberg Block show up in front end?
- Gutenberg core/file add style support in js/ json
- Working with a non-React external library in a custom block