I have a custom-post-type named wr_events
. I have quite a lot of meta-boxes in this post-type. The post-type and the meta-boxes itself work just fine.
Only thing: No matter at what post-type I create a "New post" I get quite a lot of php errors and notices …
Notice: Undefined index: _wr_event_speaker in /Users/my/htdocs/wr/wp-content/themes/wr/functions.php on line 246
Notice: Undefined index: _wr_event_date in /Users/my/htdocs/wr/wp-content/themes/wr/functions.php on line 248
Notice: Trying to get property of non-object in /Users/my/htdocs/wr/wp-content/themes/wr/functions.php on line 249
Notice: Trying to get property of non-object in /Users/my/htdocs/wr/wp-content/themes/wr/functions.php on line 250
Notice: Undefined index: _wr_event_time in /Users/my/htdocs/wr/wp-content/themes/wr/functions.php on line 250
Notice: Trying to get property of non-object in /Users/my/htdocs/wr/wp-content/themes/wr/functions.php on line 251
Notice: Undefined index: _wr_event_review in /Users/my/htdocs/wr/wp-content/themes/wr/functions.php on line 251
So even though this meta-boxes are just assigned to my "events" post-type the errors above also come up when I create a normal new post.
So again, if I click on "Add New" this messages come up. They also appear if I goto "Add New" in my custom-post-type.
Weird is, that the errors don't come up if I edit a post or a custom-post.
Any ideas what could cause that?
update:
Well I use a class for the custom metaboxes because my requirements are quite unusual. https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress
/**
* Initialize the post-meta class
*/
add_action( 'init', 'be_initialize_cmb_meta_boxes', 9999 );
function be_initialize_cmb_meta_boxes() {
if ( !class_exists( 'cmb_Meta_Box' ) ) {
require_once( 'lib/metabox/init.php' );
}
}
add_filter( 'cmb_meta_boxes', 'cmb_sample_metaboxes' );
function cmb_sample_metaboxes( array $meta_boxes ) {
$prefix = '_wr_';
$meta_boxes[] = array(
'id' => 'event_review',
'title' => 'Review',
'pages' => array( 'wr_event'),
'context' => 'normal',
'priority' => 'low',
'fields' => array(
array(
'name' => 'Review',
'id' => $prefix . 'event_review',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 5, ),
)
),
);
return $meta_boxes;
}
So, again: This works like a charm and the notices actually shouldn't bother me because everything is working fine. However I was just wondering why this notices appear on every "Add New" page.
update:
The update_post_meta()
functions throw the error.
add_action('save_post', 'save_details');
function save_details(){
global $post;
update_post_meta($post->ID, "event_review", $_POST["_wr_event_review"]);
}
/Users/my/htdocs/wr/wp-content/themes/wr/functions.php
at lines 235~260?