WordPress Menu Builder

Lately one of the project i’m involved in is having this weird issue which unable to save the whole menu items we made (The menu item saving process is suddenly ended after 80-something menu items are saved). Okay, it is idea of mine to use mega dropdown menu but i didn’t expect that it is going to have hundreds of menu item on it LOL Weirdly, it works well on local and development server. Considering this issue i think the problem is not the incapability of WordPress in handling hundreds of menu-item. I (currently) believe that the problem is on the server configuration which we’re still working on it.

However, there is a requirement to add more menu item. Since it is currently unable to save more menu-item through dashboard interface, i decided to figure out how WordPress menu works and insert the menu item directly through the database (i’m using PhpMyAdmin) while we’re working on the server configuration issue. After some couple of times messing with the database, i finally get how it works.

If you’re about to ‘directly insert‘ a menu-item to existing menu location, there are three tables that you’re going to modify: wp_posts, wp_term_relationships and wp_postmeta. However, if you’re going to see it on its bigger picture, wp_terms and wp_term_taxonomy is also involved in this.

Let’s say I’m going to add a custom menu item with “@fikrirasyid” as its label and a link to my twitter profile “http://twitter.com/fikrirasyid” as its URL.

1. Insert new record to wp_posts table

wp_posts
Click to enlarge

These are some fields you have to pay attention to:

  • ID : The ID of the item
  • post_title : Information that will be used as “label” of the menu-item
  • post_status : make sure it’s “publish”
  • post_name : Information that will be used as its slug
  • menu_order : information that is used to determine the order of the menu-item.
  • post_type : Make sure that it’s “nav_menu_item”

2. Insert new record to wp_term_relationships

wp_term_relationships
Click to enlarge

for more understanding toward wp_term_relationshipsterm_taxonomy_id field, take a look at wp_terms and wp_term_taxonomy tables below.

wp_term_taxonomy
Click to enlarge
wp_terms
Click to enlarge

3. Insert 8 new records to wp_postmeta

Finally here’s the last recipe. These 8 records on the wp_postmeta are where the values of menu-item is stored.

wp_postmeta
Click to enlarge
Menu-item fields
Click to enlarge

Anyway, there is further note you need to know for these meta_keys:

  • _menu_item_object : there is custom, pages, categories, custom taxonomies, and so on and so forth.
  • _menu_item_object_id : If the type of menu-item is page, then this meta_key will store the value of page ID (note that it’s page ID on wp_posts, not the nav_menu_item ID version of it)
  • _menu_item_menu_item_parent : the ID of parent menu item

And that’s it. To comprehend it more, it’ll be a good idea to take a look to your existing local WordPress site’s database and understand it in your own situation.

One thought on “Tables Involved in WordPress Menu Feature

  1. keren tutorialnya:)

Share Your Thought