I do not want a user to be able to publish a post if no category is selected. I don’t mind throwing a JS alert or handling this on the server side as well.
Anyway, how can I ensure this?
Note: “uncategorized” should not be chosen as well.
I do not want a user to be able to publish a post if no category is selected. I don’t mind throwing a JS alert or handling this on the server side as well.
Anyway, how can I ensure this?
Note: “uncategorized” should not be chosen as well.
Comments are closed.
You can do this easily with jQuery:
The above code will show an alert box if no category is selected. You can use dialog box instead if you’d like.
Here is my solution. I include this .js file on all Admin Pages, but since some of my custom post types don’t include categories, I handle that situation by checking and returning true at the beginning of the function. I’m not an expert at JQuery, so I wrote most of this in straight JavaScript. Note that it specifically checks for the unpublished category, as well as checking the number of categories selected.