import { useSelect } from '@wordpress/data'; const useCurrentPostCategories = () => { const categoryIds = wp.data.select('core/editor').getEditedPostAttribute('categories') return useSelect((select) => { const {getEntityRecords} = select('core') const taxonomies = getEntityRecords('taxonomy', 'category') if (!taxonomies) return [] const currentCategories = taxonomies.filter(taxonomy => { return ca
![WordPressのカスタムブロックで、その投稿のカテゴリ / タグを取得する](https://cdn-ak-scissors.b.st-hatena.com/image/square/28b51bce57df5dd8999be7ea6cd435c16b7b4e1f/height=288;version=1;width=512/https%3A%2F%2Fres.cloudinary.com%2Fzenn%2Fimage%2Fupload%2Fs--bLwnc5Cg--%2Fc_fit%252Cg_north_west%252Cl_text%3Anotosansjp-medium.otf_55%3AWordPress%2525E3%252581%2525AE%2525E3%252582%2525AB%2525E3%252582%2525B9%2525E3%252582%2525BF%2525E3%252583%2525A0%2525E3%252583%252596%2525E3%252583%2525AD%2525E3%252583%252583%2525E3%252582%2525AF%2525E3%252581%2525A7%2525E3%252580%252581%2525E3%252581%25259D%2525E3%252581%2525AE%2525E6%25258A%252595%2525E7%2525A8%2525BF%2525E3%252581%2525AE%2525E3%252582%2525AB%2525E3%252583%252586%2525E3%252582%2525B4%2525E3%252583%2525AA%252520%25252F%252520%2525E3%252582%2525BF%2525E3%252582%2525B0%2525E3%252582%252592%2525E5%25258F%252596%2525E5%2525BE%252597%2525E3%252581%252599%2525E3%252582%25258B%252Cw_1010%252Cx_90%252Cy_100%2Fg_south_west%252Cl_text%3Anotosansjp-medium.otf_37%3Ahidetaka%252520okamoto%252Cx_203%252Cy_121%2Fg_south_west%252Ch_90%252Cl_fetch%3AaHR0cHM6Ly9saDMuZ29vZ2xldXNlcmNvbnRlbnQuY29tL2EtL0FPaDE0R2pBNDNNV05WYlQ5Y2ZKeDJTRElqbDMxZGZGV1RDa252NnI5dm11ZWpvPXMyNTAtYw%3D%3D%252Cr_max%252Cw_90%252Cx_87%252Cy_95%2Fv1627283836%2Fdefault%2Fog-base-w1200-v2.png)