Index: local_menu.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/local_menu/local_menu.module,v
retrieving revision 1.12
diff -u -r1.12 local_menu.module
--- local_menu.module	21 Jul 2009 20:09:00 -0000	1.12
+++ local_menu.module	28 Aug 2009 01:50:20 -0000
@@ -66,16 +66,28 @@
       return FALSE;
     }
 
-    // Get the menu link and set the active menu to the menu it's in, so Drupal can find it's way and make correct breadcrumbs at the same time
-    $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path = '%s' AND hidden <> 1 AND menu_name NOT IN ('admin_menu', 'devel')", $item['href']);
+    // for consistency, we will order these results to match against primary, secondary, active menus,
+    // with preference for the active menu, then primary, then secondary
+    $active_menu_name    = menu_get_active_menu_name() ;
+    $primary_menu_name   = variable_get('menu_primary_links_source', 'primary-links') ;
+    $secondary_menu_name = variable_get('menu_secondary_links_source', 'secondary-links') ;
 
+    // Get the menu link and set the active menu to the menu it's in, so Drupal can find it's way and make correct breadcrumbs at the same time
+    $sql = "
+  SELECT mlid
+    FROM {menu_links}
+   WHERE link_path = '%s'
+     AND hidden <> 1
+     AND menu_name NOT IN ('admin_menu', 'devel')
+ORDER BY menu_name = '%s' DESC, menu_name = '%s' DESC, menu_name = '%s' DESC
+" ;
+    $result = db_query($sql, $item['href'], $active_menu_name, $primary_menu_name, $secondary_menu_name);
     // In case there are multiple, let's find the most appropriate one
     while ($link = menu_link_load(db_result($result))) {
-
       if (in_array($link['menu_name'], array(
-            variable_get('menu_primary_links_source', 'primary-links'),
-            variable_get('menu_secondary_links_source', 'secondary-links'),
-            menu_get_active_menu_name(),
+            $active_menu,
+            $primary_menu_name,
+            $secondary_menu_name,
           ))) {
         break;
       }
