Hello what can I do I somehow get the following error on the custom panel at admin panel. Normally there is no problem on the menu. I only get an error when I enter the Customize page to live the theme live.
Fatal error: Uncaught exception 'Exception' with message 'Supplied nav_menu_item value missing property: target' in L:\UwAmp\www\Wordpress\News\wp-includes\customize\class-wp-customize-nav-menu-item-setting.php on line 183
I take the fault both locally and on the server
Where I got the error: wp-admin/customize.php
Code in function.php file:
if(!is_admin()){
add_filter( 'wp_get_nav_menu_items', 'display_lasts_ten_posts_for_categories_menu_item', 10, 3 );
}
function display_lasts_ten_posts_for_categories_menu_item( $items, $menu, $args ) {
if ( is_admin() ) {
return $items;
}
$menu_order = count($items);
$child_items = array();
foreach ( $items as $item ) {
if ( 'category' != $item->object || ('category' == $item->object && get_category_children($item->object_id)) )
continue;
$category_ten_last_posts = array(
'numberposts' => 4,
'cat' => $item->object_id,
'orderby' => 'date',
'order' => 'DESC'
);
foreach ( get_posts( $category_ten_last_posts ) as $post ) {
$post->menu_item_parent = $item->ID;
$post->post_type = 'nav_menu_item';
$post->object = 'header-lasts';
$post->type = 'header-lasts';
$post->menu_order = ++$menu_order;
$post->title = get_the_post_thumbnail( $post->ID ) . ' ' .$post->post_title;
$post->url = get_permalink( $post->ID );
$child_items[]= $post;
}
}
return array_merge( $items, $child_items );
}
Hello what can I do I somehow get the following error on the custom panel at admin panel. Normally there is no problem on the menu. I only get an error when I enter the Customize page to live the theme live.
Fatal error: Uncaught exception 'Exception' with message 'Supplied nav_menu_item value missing property: target' in L:\UwAmp\www\Wordpress\News\wp-includes\customize\class-wp-customize-nav-menu-item-setting.php on line 183
I take the fault both locally and on the server
Where I got the error: wp-admin/customize.php
Code in function.php file:
if(!is_admin()){
add_filter( 'wp_get_nav_menu_items', 'display_lasts_ten_posts_for_categories_menu_item', 10, 3 );
}
function display_lasts_ten_posts_for_categories_menu_item( $items, $menu, $args ) {
if ( is_admin() ) {
return $items;
}
$menu_order = count($items);
$child_items = array();
foreach ( $items as $item ) {
if ( 'category' != $item->object || ('category' == $item->object && get_category_children($item->object_id)) )
continue;
$category_ten_last_posts = array(
'numberposts' => 4,
'cat' => $item->object_id,
'orderby' => 'date',
'order' => 'DESC'
);
foreach ( get_posts( $category_ten_last_posts ) as $post ) {
$post->menu_item_parent = $item->ID;
$post->post_type = 'nav_menu_item';
$post->object = 'header-lasts';
$post->type = 'header-lasts';
$post->menu_order = ++$menu_order;
$post->title = get_the_post_thumbnail( $post->ID ) . ' ' .$post->post_title;
$post->url = get_permalink( $post->ID );
$child_items[]= $post;
}
}
return array_merge( $items, $child_items );
}
Share
Improve this question
asked May 28, 2018 at 15:52
Kamil AykiriKamil Aykiri
211 bronze badge
1 Answer
Reset to default 1I was getting the same fatal error after creating a similar dynamic menu. What fixed the issue for me was redefining the default values:
$post->target = '';
$post->attr_title = '';
$post->description = '';
$post->classes = '';
$post->xfn = '';
$post->status = 'publish';
$post->original_title = '';
So your foreach loop would look like this:
foreach ( get_posts( $category_ten_last_posts ) as $post ) {
$post->menu_item_parent = $item->ID;
$post->post_type = 'nav_menu_item';
$post->object = 'header-lasts';
$post->type = 'header-lasts';
$post->menu_order = ++$menu_order;
$post->title = get_the_post_thumbnail( $post->ID ) . ' ' .$post->post_title;
$post->url = get_permalink( $post->ID );
$post->target = '';
$post->attr_title = '';
$post->description = '';
$post->classes = '';
$post->xfn = '';
$post->status = 'publish';
$post->original_title = '';
$child_items[]= $post;
}