I am using the following functions to get the selected category objects. It seems to always return no matches even though there are several. What am I missing here?
(function (wp) { const { useSelect, select, dispatch } = wp.data; const { subscribe } = wp.data; function getSelectedCategories() { const selectedCategories = select('core/editor').getEditedPostAttribute('categories'); const categories = select('core').getEntityRecords('taxonomy', 'category'); if (!categories || !selectedCategories || selectedCategories.length === 0) { return []; } return categories.filter(cat => selectedCategories.includes(cat.id)); } }
useSelect
react hook? It's very rare to see block editor components directly interfacing with data stores like that. Also what's the context this is being used in? Where and how this is used is very important but that information is missing here