admin管理员组

文章数量:1300023

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


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.

本文标签: metaboxPost and Pages section inside WordPress admin are completely blank