最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

block editor - get selected categories or tags (using javascript) in GutenBerg?

matteradmin10PV0评论

I was still unable to find out that in Gutenberg. Specifically, i used:

wp.data.select("core/editor").getPostEdits();

to find out how many categories were checked. But it missed already checked categories... So, which function should I use to access in sum, how many categories are select at this moment? where is that data stored?

I was still unable to find out that in Gutenberg. Specifically, i used:

wp.data.select("core/editor").getPostEdits();

to find out how many categories were checked. But it missed already checked categories... So, which function should I use to access in sum, how many categories are select at this moment? where is that data stored?

Share Improve this question edited Apr 13, 2019 at 7:38 T.Todua asked Jan 3, 2019 at 17:29 T.ToduaT.Todua 5,8809 gold badges52 silver badges81 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 6

To get the categories from inside the editor of a post you can make use of the following selectors:

The categories the post has in the published version: wp.data.select("core/editor").getCurrentPostAttribute("categories")

The current categories of the edit (for example if the user has selected a new category but hasn't saved the post it will appear with this selector but not with the former): wp.data.select("core/editor").getEditedPostAttribute("categories")

This will give you an array with the id of each category.

Post a comment

comment list (0)

  1. No comments so far