I'm new to Wordpress. I created a custom post type in a plugin and I'm trying to add a custom validation to it.
Before saving a new post of this type (in admin), I'd like to check if the submitted post title already exists. So that's what I thought it could be:
Is this logic correct? If not, how should it be?
As I'm new to Wordpress, I'm not using a OOP approach, at least not yet.
Thanks!
Well, it seems that my proposed logic is invalid.
Also, looks like the only way of preventing a post being saved is if you validate the form using JavaScript.
The closer answer I could find is this one. And yet it doesn't cover validation if the user is quick editing the post.
So, again, using JavaScript for validation seems to be the best option - at least in this case, which does not contain a more complicated field like a file upload.
Thanks for helping!
EDIT: The Duplicate Title Checker plugin gives an idea on how to do it with JS.