Support » Fixing WordPress » Validating post fields and taxonomy before save

  • Hi,

    What is, in your opinion, the best and most elegant way to add content validation to a custom type post? I need to verify, before a post of a specific custom post type is saved that if a specific custom taxonomy is checked that there’s a value in a specific custom text field, etc.

    Thanks a lot,
    Yuval Khalifa

Viewing 2 replies - 1 through 2 (of 2 total)
  • Khalifa,

    I would recommend you to following the sanitization and escaping to validate and secure your content.

    https://codex.wordpress.org/Validating_Sanitizing_and_Escaping_User_Data

    Hi,

    Thanks. I’ve already read that article and although it is very important it is not what I was looking for.

    I’m trying to enforce a certain logic before the post is saved, for example let’s say that I’m using WordPress to keep track of my animals in a small zoo. I have a custom post type called “animal” that contains a list of custom fields assigned to it like name, id, herbivorous_food, carnivorous_food. This custom post type also has custom taxonomy assigned to it called “prey_type” and contains three possible values like herbivorous, carnivorous and omnivorous.

    Now, for example, if I’m currently creating a post for a fox, I’ll write fruits and seeds in the herbivorous_food and mice and rats under carnivorous_food and I’ll select omnivorous in the prey_type taxonomy.

    What I need is a way to verify that if both fields (herbivorous_food and carnivorous_food) contain value the user will get an alert when he/she tries to save the post unless the only taxonomy that is selected is omnivorous, and if only carnivorous_food contains value than the user will get an alert when he/she tries to save the post unless the only taxonomy that is selected is carnivorous and so on.

    Is that possible? If so – how?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Validating post fields and taxonomy before save’ is closed to new replies.