UNPKG

@wordpress/block-library

Version:
37 lines (36 loc) • 924 B
import { store } from "@wordpress/core-data"; import { useSelect } from "@wordpress/data"; // packages/block-library/src/post-terms/use-post-terms.js const EMPTY_ARRAY = []; function usePostTerms({ postId, term }) { const { slug } = term; return useSelect((select) => { if (!term?.visibility?.publicly_queryable || !postId) return { postTerms: EMPTY_ARRAY, isLoading: false, hasPostTerms: false }; const { getEntityRecords, isResolving } = select(store); const taxonomyArgs = [ "taxonomy", slug, { post: postId, per_page: -1, context: "view" } ]; const terms = getEntityRecords(...taxonomyArgs); return { postTerms: terms, isLoading: isResolving("getEntityRecords", taxonomyArgs), hasPostTerms: !!terms?.length }; }, [ postId, term?.visibility?.publicly_queryable, slug ]); } export { usePostTerms as default }; //# sourceMappingURL=use-post-terms.mjs.map