我使用以下方法成功地将所有帖子(自定义帖子类型)添加到我的wordpress菜单:https://codeseekah.com/2012/03/05/list-all-posts-in-wordpress-navigation-menu/
一切都很顺利。不幸的是,在wp admin中保存菜单时出现此错误:“The given object ID is not that of a menu item.“我得到了一个长列表,其中大约有20个(每个菜单项都有一个错误)。
这是我的函数文件中的内容:
/**
* List all posts in wp nav menu
* @link https://codeseekah.com/2012/03/05/list-all-posts-in-wordpress-navigation-menu/
* @param [type] $items [description]
* @param [type] $menu [description]
* @param [type] $args [description]
* @return [type] [description]
*/
/* take care of the urls */
add_filter( \'wp_get_nav_menu_items\', \'services_menu_filter\', 12, 3 );
function services_menu_filter( $items, $menu, $args ) {
/* alter the URL for cpt-archive objects */
$menu_order = count($items); /* Offset menu order */
$child_items = array();
foreach ( $items as &$item ) {
if ( $item->title != \'##services##\' ) continue;
$item->url = \'/services/\';
$item->title = \'Services\';
foreach ( get_posts( \'post_type=services&numberposts=-1\' ) as $post ) {
$post->menu_item_parent = $item->ID;
$post->post_type = \'nav_menu_item\';
$post->object = \'custom\';
$post->type = \'custom\';
$post->menu_order = ++$menu_order;
$post->title = $post->post_title;
$post->url = get_permalink( $post->ID );
/* add children */
$child_items []= $post;
}
}
return array_merge( $items, $child_items );
}
有没有办法摆脱wordpress菜单错误通知?一切都很好,我可以接受,但我不想在客户看到所有错误时甩掉他们。是的,我想过用CSS隐藏错误,但这还不够好。web主机是Kinsta。我尝试将以下内容添加到wp config。php:
/** Memory Limit */
define(\'WP_MEMORY_LIMIT\', \'128M\');
谢谢!