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
- What are all the query parameters for getEntityRecords?
- Is there a core Sortable component in Gutenberg?
- Is there an equivalent of the PHP function sanitize_key in Gutenberg?
- Is there a client side API for handling transients or options?
- Updata Metadata WP Rest API
- What do the args for Gutenberg subpackage “hooks” function “doAction” mean?
- How do I fire a snackbar notice in admin?
- Gutenberg Modify core taxonomy panel element via wp.hooks.addFilter
- Get HTTP response code on non-2xx apiFetch request
- What is “open()” in MediaUpload?
- Why is this gutenberg custom format button only available from the toolbar as a dropdown?
- Adding a text element in between title and blocks container
- Setting HTML properties in a Gutenberg plugin using WordPress settings
- Provide specific example for block variation
- Block editor: How to check if block editor has initialized and populated the data store?
- How to get value of selected page template in Gutenberg editor?
- @wordpress/components Button variants not styled
- Block Editor: How to get title and post content within the WordPress admin UI in Javascript?
- Custom block SelectControl works but equivalent ComboboxControl gives errors – where’s my mistake?
- Gutenberg passing block attributes to component in ES6/ESNext
- How can I add Block Style support to the core HTML block in Gutenberg?
- WP REST API Post Status Using JavaScript
- can a buttongroup have a label?
- Script Localization doesn’t work
- InnerBlocks restricting does not work on nested blocks
- Gutenberg: Block validation Failed Richtext undefined
- Add A Tag To A Post Through JavaScript In Gutenberg UI?
- Add custom HTML markup to Gutenberg RichText
- Authentication with the Rest API when using an External Application
- How to return div with custom attributes(Coding a Gutenberg Block)
- Setting/unsetting terms using the Backbone JavaScript client
- Open Featured Image Modal in WordPress Gutenberg onClick of a button
- 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?
- How can I import one custom block into another?
- Gutenberg Blocks: how to determine an index of the current inner block?
- 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
- Gutenberg select excerpt, use generated excerpt or use more block excerpt
- 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
- find out reason of “Updating failed” in Post-editor
- How to render WP Rest-API Endpoints in a React.js Theme with Woocommerce
- How to read inline-CSS from Gutenberg block?
- 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
- Add a Page Screen is Visually Blank
- 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
- Issue migrating a checkbox-type meta field to the block editor
- [Vue warn]: Error in render: “TypeError: Cannot read property ‘wp:featuredmedia’ of undefined – REST API
- Gutenberg – dynamically created element: how to set onChange?
- Get user in rest API endpoint
- Custom block update rendering when reused
- WordPress Gutenberg Ajax request
- How to improve WP-Rest atrocious response time?
- How should I identify the inline javascript that is the dependent of a wp_enqueue_script?
- Gutenberg Edit Block Inspector Controls and save
- Spans in gutenberg
- Block pattern conflict with custom block
- WordPress REST API response is empty in browser and script, but not in Postman
- How to delete child block for associated parent block
- Passing object to FormTokenField suggestions
- How to detect if we are in the Site Editor part of the Block Editor (as opposed to editing a Page/Post) in JavaScript?
- How can I show a Slot/Fill in the block editor
- How to add more elements to an already existing section in Gutenberg
- How do i get an Inline style in Gutenberg Block show up in front end?
- WordPress adds and tags into HTML blocks after saving
- Get Comment Text via REST API
- Gutenberg core/file add style support in js/ json
- How to add a css class to postTitleWrapper in Gutenberg?
- Masonry gallery block is working in the block editor but not the template editor
- How to import the imagesLoaded and Masonry libs that come with WP in a Gutenberg block?
- Additional CSS classes not being added in Gutenberg editor
- How do I filter/modify the updated content on save using javascript?
- How to execute some javascript code in the editor when a block pattern is added?
- How to add an additional dependency to a block index.asset.php file
- Why is the Gutenberg editor not recognizing my updates?
- Update a server-side render Block when woocommerce cart block changed
- useSelect() plus resolver result is serving cached data incorrectly