Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

There are 3 menus in my wordpress(3.5) now.

  • Main menu (default from wp)
  • Footer menu (default from wp)
  • Test menu

Now I have kept test menu as default.

Where does Wordpress store this thing?

I want to know where wordpress stores about current menu that is displaying in the front end.

share|improve this question

1 Answer 1

up vote 8 down vote accepted

Menu by itself is a taxonomy in WP. It means that you can find all menus in wp_terms table, by running following query:

SELECT * 
  FROM wp_terms AS t
  LEFT JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id
 WHERE tt.taxonomy = 'nav_menu';

Menu item is custom post type in WP. They are stored in wp_posts table. You can find all of them by using this query:

SELECT * 
  FROM wp_posts 
 WHERE post_type = 'nav_menu_item';

Relations between menus and menu items are stored in wp_term_relationships table. To find all items of specific menu you can use this query:

SELECT p.* 
  FROM wp_posts AS p 
  LEFT JOIN wp_term_relationships AS tr ON tr.object_id = p.ID
  LEFT JOIN wp_term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
 WHERE p.post_type = 'nav_menu_item'
   AND tt.term_id = /*your menu ID*/;

Information about currently select menu is located in wp_options table as serialized PHP array. For example if we use TwentyEleven theme, then we will have a record in wp_options table with option_name column equals to theme_mod_twentyeleven and option_value column equals to ...;s:18:"nav_menu_locations";a:1:{s:7:"primary";i:103;}}. Here you can see that menu with term_id equals to 103 is currently selected as "primary" menu.

The key principle here is that we always have separate options record for each WP theme. Such options have the same name structure: theme_mods_{your-theme-name}.

P.S.: To change current menu in the admin panel, just go to Appearance » Menus page and select menu you need in Theme Locations meta box:

enter image description here

share|improve this answer
    
Thanks for your reply but I want to know where it stores the menu which is default (showing to front end) now. –  Hiren Rathod Jan 5 '13 at 12:04
    
@HirenRathod I have updated my answer –  Eugene Manuilov Jan 5 '13 at 12:23
    
+1 for line "Menu by itself is a taxonomy in WP".. –  Rajeev Vyas Jan 5 '13 at 12:35
    
Yes, I got the answer. I'm using hypershot theme and kept primery menu as test menu. It stores like this a:2:{i:0;b:0;s:18:"nav_menu_locations";a:2:{s:11:"header-menu";i:27;s:11:"footer‌​-menu";i:0;}} Here i:27 means 27 is the term_id from wp_terms. Thanks @eugene-manuilov :) –  Hiren Rathod Jan 6 '13 at 19:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.