-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
enhancementNew feature or requestNew feature or request
Description
If a taxonomy has capabilities set, useSelect won't return the terms due to a rest_forbidden_context error. Could we have an option to pass a prop to toggle between using apiFetch and useSelect in cases where we might need to maintain capability restrictions but still be able to fetch terms?
import apiFetch from '@wordpress/api-fetch';
...
const [ apiData, setApiData ] = useState( null );
/**
* Get all taxonomies of slug type
*/
useEffect( () => {
if ( ! useApiFetch ) {
return;
}
apiFetch( { path: `/wp/v2/${ slug }` } ).then( ( posts ) => {
setApiData( posts );
} );
}, [ slug, useApiFetch ] );
const selectData = useSelect(
( select ) => {
return select( 'core' ).getEntityRecords( 'taxonomy', slug, {
per_page: -1,
} );
},
[ slug ]
);
const data = useApiFetch ? apiData : selectData;
<TaxonomyControl
...
useApiFetch={ true }
/>
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request