0

Meta Tags - Undefined array due to meta tags!

I have created my own custom post meta tags but all works fine until I test my WordPress theme on the new WordPress Installation.

What I came through after the new WordPress installation, I have activated my theme, and when I try to open post or pages section inside WordPress admin. It triggers an errors

1. Warning: Undefined array key "your_meta_box_nonce"

I solved it by adding -> [ isset($_POST['your_meta_box_nonce']) && ] inside first condition

function save_your_fields_meta( $post_id ) {
  // verify nonce
  if ( [ --Added Here-- ] !wp_verify_nonce( $_POST['your_meta_box_nonce'], basename(__FILE__) ) ) {
    return $post_id;
  }
  
}
add_action( 'save_post', 'save_your_fields_meta' );

2. Warning: Undefined array key "post_type" and Warning: Undefined array key "your_fields"

I soved it by adding -> [ isset($_POST['post_type']) && ]

// check permissions
  if ( [ --Added Here-- ] 'page' === $_POST['post_type'] ) {
    if ( !current_user_can( 'edit_page', $post_id ) ) {
      return $post_id;
    } elseif ( !current_user_can( 'edit_post', $post_id ) ) {
      return $post_id;
    }
  }

and -> [ isset($_POST['your_fields']) && ]

if ( [ --Added Here-- ] $_POST['your_fields'] !== $old ) {
    update_post_meta( $post_id, 'your_fields', $_POST['your_fields'] );
  } elseif ( isset($_POST['your_fields']) && '' === $_POST['your_fields'] && $old ) {
    delete_post_meta( $post_id, 'your_fields', $old );
  }

Errors are solved but the page is completely blank.

Below is my full code of the meta save_post function

https://pastebin.com/NSnvEPcn


Update -:

I have checked my code again and set my define(‘WP_DEBUG’, true); but it still does not show an error means the blank page.

So I tried to hide my code and when I did it. I found that when I set priority to default, core, high, low it triggers gets blank but when I set priority to any numeric value it appears again but obesity it did not display the custom meta box

Below is the complete code of my custom meta field.

https://pastebin.com/ZWvV9vKe

2
  • A blank page suggests a fatal php error. In wp-config.php add the line define(‘WP_DEBUG’, true); to show the errors and try loading the page again – Andy Macaulay-Brook Mar 26 at 16:52
  • Still the blank page – Owaiz Yusufi Mar 27 at 6:53

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.