Possible Duplicate:
don't publish custom post type post if a meta data field isn't valid

A custom post type is being developed in wordpress. It is needed that some fields should be made mandatory. Is there a method in Api using which posts fields could be made mandatory? Or it would need to be done using custom code?


I am making a custom post type for an Event. Now when creating a new Event it is mandatory that the user enters the date, otherwise it should not allow to save him the event.

  • I was pretty sure there's a duplicate of this one, but can't seem to find it. Using an API Method is custom code. I suggest you to add details to your Question, what fields are you talking about? How's your CPT being developed? Otherwise, IMO, the Q is overly broad...
    – brasofilo
    Commented Jul 18, 2012 at 17:44
  • made the question a little more informative. Commented Jul 18, 2012 at 18:00

1 Answer 1


agree that the question is broad. first thought is you could hook into pre_post_update and check for the presence of the fields you require. if they are there, save the post. if they are not there, then do not save, but generate an admin notice.

edit: based on comments, save_post is too late, so i've amended the answer to say pre_post_update

  • Almost correct accept save_post hook is fired after the post is already saved
    – Bainternet
    Commented Jul 18, 2012 at 18:06
  • Try using pre_post_update Commented Jul 18, 2012 at 18:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.