block editor – How can I prevent a user from selecting exactly one of two (not both or none) categories on a post?


I have Categories A, B, C, D and E.

When creating a post, I want the user to be able to check of either A or B, but not one or both and 0 or more other categories. And I want Category A to be checked by default when they open the page if this is a new post. If it’s an existing post, the categories should reflect the existing categories.

I initially tried pulling this off with some jQuery but ran into some serious roadblocks.

I’d prefer to allow the user to get immediate feedback and allow them to see categories A/B toggle themselves on an off. But I don’t know react. Not sure if I have any good options besides writing some PHP code on the save_post hook and sending back an error if the user fails to select either Category A or B, or neither, or both.

StevieD 1 month 2023-02-19T20:38:39-05:00 0 Answers 0 views 0

Leave an answer