wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



update_menu_item_cache › WordPress Function

Depuis6.1.0
Dépréciéen/a
update_menu_item_cache ( $menu_items )
Paramètres:
  • (WP_Post[]) $menu_items Array of menu item post objects.
    Requis: Oui
Défini(e) dans:
Codex:

Updates post and term caches for all linked objects for a list of menu items.



Source

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