I'm using WordPress and I want to add validation for the save_meta_data function and if the request isn't validated admin panel should show the error message. my code is here:

public function save_meta_data()
if (isset($_POST['isbn'])) {
    $isbn = sanitize_text_field($_POST['isbn']);
    if($_POST['isbn'] == '1234567890987' )
        add_action( 'admin_notices', array($this,'my_error_notice') );
function my_error_notice() {
<div class="error notice">
    <p><?php _e( 'There has been an error. Bummer!', 'my_plugin_textdomain' ); ?></p>

I didn't get any notice when I call add_action inside the save_meta_data function. How should I fix this?

  • 1
    Which hook does save_meta_data run in? Jun 26 '21 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.