0

I have a custom CPT and I need that my user fill all the required fields.
How can I check if the field is set and show a message error if is not set?

I have a custom hook to the save_post action that check if is my CPT, there is any action for show error box and prevent create post?

1 Answer 1

0

You can check post data in $_POST array on save_post_{custom_post_type_name} action hook.

And if data is not appropriate or according to server side validation and redirect page with custom error args using wp_redirect and , you can grab the errors and display admin notices using admin_notice.

1
  • Thanks @kapil, the problem is that the hook is execute even if is a new post so I get a loop. How can I execute that hook only after the submit event? Commented Nov 3, 2016 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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