WP_GET_NAV_MENU_ITEMS wp-admin/Customize.php问题

时间:2018-05-28 作者:Kamil Aykiri

您好,我该怎么办?我在“管理”面板的“自定义”面板上不知何故出现以下错误。通常菜单上没有问题。我只有在进入自定义页面以直播主题直播时才会出错。

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
我在本地和服务器上都接受故障

Where I got the error: wp管理/自定义。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 );
}

1 个回复
SO网友:mcrockets

在创建了类似的动态菜单之后,我遇到了同样的致命错误。解决这个问题的方法是重新定义默认值:

$post->target = \'\';
$post->attr_title = \'\';
$post->description = \'\';
$post->classes = \'\';
$post->xfn = \'\';
$post->status = \'publish\';
$post->original_title = \'\';
因此,您的foreach循环如下所示:

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;
}

结束

相关推荐

Count > 1 Navigation Slider

我有一个帖子类型slider, 当您有多个帖子要显示导航时。我的代码:<?php $count_slider = wp_count_posts(\'slider\'); echo $count_slider->publish; ?> <?php if($count_slider > 1): ?> <div id=\"slideshowcontrol\" class=\"clearfi