Skip to content

Instantly share code, notes, and snippets.

@John2496
Last active December 28, 2015 01:39
Show Gist options
  • Save John2496/7421901 to your computer and use it in GitHub Desktop.
Save John2496/7421901 to your computer and use it in GitHub Desktop.
batch update breadcrumb structure
<?php
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->propertyCondition('type', 'news')
->execute();
$item_nids = array_keys($result['node']);
$items = entity_load('node', $item_nids);
foreach ($items as $node_id => $row) {
$menu_result = db_select('menu_links', 'm')
->fields('m')
->condition('link_path', "node/{$node_id}")
->execute()
->fetchAssoc();
if (!$menu_result) {
$menu_item = array(
'link_path' => 'node/' . $node_id,
'link_title' => $row->title,
'menu_name' => 'main-menu',
'plid' => 407
);
menu_link_save($menu_item);
}
}
menu_cache_clear('main-menu');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment