0

I've a function attach to the save post custom post type hook and when I add a custom post type everything is fine. But when I edit it and update it only a part of my function works

add_action('save_post_$custom' , 'example')

function example() {

$errors = validation_function();

  if ($erros) {
    return $post_id;
  } else {
    update meta logic
  }
}

On add post the $errors verification and update meta method works, but on edit post the errors verification doesn't work but the update meta logic does work.

So it's not the problem of hook not firing I've no clues.

Any ideas ?

2
  • and what is validation_function() ?
    – vancoder
    Commented Dec 8, 2020 at 19:18
  • A simple function to check if var is isset else It adds an error using WP Error object
    – DrK
    Commented Dec 8, 2020 at 22:44

1 Answer 1

0

I find out the problem

if(isset($_POST['publish']))

Conditionnal statement around my error validation function, this variable doesn't exist on updating post.

Is there a official Wordpress way to check if a form is submitted in adding and editing posts ?

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.