Support Forum
Support › General › ✅My custom metabox stops working on WP 4.9.8 › Reply To: My custom metabox stops working on WP 4.9.8
Thanks for troubleshooting this with me. I'm at the point now where I can see the fields I want in the admin... but when I try and save the post, I get a bunch of notices and the post won't save (Notice: Undefined index: clone in /phila.gov/wp/wp-content/plugins/meta-box/inc/meta-box.php on line 301)
. Here's what I'm working with on the latest version of metabox:
if ( class_exists( 'RWMB_Field' ) ) {
class RWMB_Unit_Field extends RWMB_Checkbox_List_Field {
public static function normalize( $field ) {
if( isset($_GET['post']) && get_post($_GET['post']) && isset($_GET['action']) && 'edit' == $_GET['action'] )
$post = get_post($_GET['post']);
if( isset($post)
&& !empty($post->post_type)
&& is_object_in_taxonomy($post->post_type, 'category')
){
foreach ( (array) get_the_category($post->ID) as $cat ) {
if ( empty($cat->slug ) )
continue;
//get data out of term meta field for use later
$units[] = rwmb_meta( 'department_units', array( 'object_type' => 'term' ), $cat->term_id);
}
}
if ( !isset( $units ) )
return;
foreach ($units as $key => $value){
foreach($value as $name) {
$options[] = array(
'value' => urlencode($name['name']),
'label' => $cat->name . ' - ' . $name['name']
);
}
}
$field = parent::normalize( $field );
return $field;
}
/*Old, working version
public static function filter_options( $field, $options ) {
$current_cats = get_the_category();
foreach($current_cats as $cat){
$units[$cat->name] = rwmb_meta( 'department_units', array( 'object_type' => 'term' ), $cat->term_id );
}
if ( !isset( $units ) )
return;
$options = [];
foreach ($units as $key => $value){
foreach($value as $name) {
$options[] = (object) array( 'value' => urlencode($name['name']), 'label' => $key . ' - ' . $name['name'] );
}
}
return $options;
}
*/
}
}