
WordPress REST API入门基础知识点
update_menu_item_cache ( $menu_items )
update_menu_item_cache: 这个函数更新当前站点的菜单项数据的缓存。每当一个菜单项被创建、更新或删除时,它就被调用。
更新一个菜单项列表的所有链接对象的后缓存和术语缓存。
function update_menu_item_cache( $menu_items ) { $post_ids = array(); $term_ids = array(); foreach ( $menu_items as $menu_item ) { if ( 'nav_menu_item' !== $menu_item->post_type ) { continue; } $object_id = get_post_meta( $menu_item->ID, '_menu_item_object_id', true ); $type = get_post_meta( $menu_item->ID, '_menu_item_type', true ); if ( 'post_type' === $type ) { $post_ids[] = (int) $object_id; } elseif ( 'taxonomy' === $type ) { $term_ids[] = (int) $object_id; } } if ( ! empty( $post_ids ) ) { _prime_post_caches( $post_ids, false ); } if ( ! empty( $term_ids ) ) { _prime_term_caches( $term_ids ); } }