MySQL Wordpress 3.0 数据库中保存的自定义菜单在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3767725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where are Custom Menus saved in the Database for Wordpress 3.0?
提问by Marc
I've been searching and searching my sql database in phpmyadmin but I can't seem to find where custom menus are stored in the database. Anyone know where it's stored? I have a large menu basically that takes forever to create. I'm in development now and rather than recreating it in production I want to try and copy the sql over to see if it works. Thanks!
我一直在 phpmyadmin 中搜索和搜索我的 sql 数据库,但我似乎无法找到自定义菜单在数据库中的存储位置。有谁知道存放在哪里吗?我有一个基本上需要永远创建的大菜单。我现在正在开发中,而不是在生产中重新创建它,我想尝试复制 sql 以查看它是否有效。谢谢!
采纳答案by ellroy35
The actual menu titles, IDs, and names are stored in the wp_terms table.
实际的菜单标题、ID 和名称存储在 wp_terms 表中。
回答by Hiren Rathod
When new custom menu is added, its entry is added into several tables.
添加新的自定义菜单时,其条目将添加到多个表中。
- table:
_term_taxonomy
with a columntaxonomy
and valuenav_menu
. - from 1)
term_id
is also in table:_terms
with the title of menu which is shown in admin panel - table:
_term_relationship
will containterm_texonomy_id
from 1) and connection to all object_id which will be linked to all_post
table havingsub_menu
and below level menu. - table:
_postmeta
will contain all the details related to menu and submenu for eachobject_id
from_posts
table.
- 表:
_term_taxonomy
带有列taxonomy
和值nav_menu
。 - 来自 1)
term_id
也在表格中:_terms
菜单标题显示在管理面板中 - 表:
_term_relationship
将包含term_texonomy_id
从 1) 到所有 object_id 的连接,这些对象将链接到所有_post
具有sub_menu
和以下级别菜单的表。 - 表:
_postmeta
包含所有与菜单和子菜单的每个细节object_id
,从_posts
表中。
回答by Todd Moses
Navigation menu items are stored in the wp_posts table with post_type = 'nav_menu_item'
.
导航菜单项存储在 wp_posts 表中,扩展名为post_type = 'nav_menu_item'
.
回答by Jay D.
I hate to bump a old thread. But if anyone runs into this like I did searching for the answer, as of WP 3.2
the post_type
for menu is now called nav_menu_item
in the wp_posts
table. They didn't have that on the wp page, they just had nav_menu
. Which I couldn't find.
我讨厌撞旧线程。但是,如果有人像我在寻找答案时那样遇到这种情况,那么现在 在表中调用WP 3.2
了post_type
for 菜单。他们在 wp 页面上没有那个,他们只有. 我找不到。nav_menu_item
wp_posts
nav_menu
回答by chuck reynolds
The custom menu links are in the wp_postmeta
table under "meta_value"
meta_key = _menu_item_url
自定义菜单链接位于
meta_key = _menu_item_urlwp_postmeta
下的表中"meta_value"
回答by Doyle Lewis
I wanted to provide a more complete and up to date answer for people who stumble upon this post like I did. There are several places in the database that need to be checked/updated if you're wanting to manually insert or update menu items.
我想为像我一样偶然发现这篇文章的人提供一个更完整和最新的答案。如果您想手动插入或更新菜单项,数据库中有几个地方需要检查/更新。
The first step is finding your main menu container. This is stored in wp_terms
. Just search by name
for the name of your menu. Take note of the ID. In my example this will be 33
. Likewise, you could insert a new row here to create a new menu. The slug can't have spaces in it. Just substitute in -
instead.
第一步是找到您的主菜单容器。这存储在wp_terms
. 只需搜索name
菜单名称即可。记下身。在我的示例中,这将是33
. 同样,您可以在此处插入新行以创建新菜单。slug里面不能有空格。只需替换即可-
。
Now we'll get to finding items in that menu. Those are stored in wp_posts
with a post_type
of nav_menu_item
. There's nothing in this table that ties it to your ID above, so you'll have to go by post_title
. If the goal is inserting a new menu item, with phpMyAdmin you can just click Copy
on an existing item in any menu and change post_title
and post_name
. Now take note of the ID of the item you inserted. Mine is 9179. It will also be nice to take note of the ID of the item you copied (even better if it was from the same menu) as we'll be using that in the next step.
现在我们将开始在该菜单中查找项目。这些存储在wp_posts
一个post_type
of 中nav_menu_item
。此表中没有任何内容将其与上面的 ID 联系起来,因此您必须通过post_title
。如果目标是插入新菜单项,使用 phpMyAdmin,您只需单击Copy
任何菜单中的现有项并更改post_title
和post_name
。现在记下您插入的项目的 ID。我的是 9179。记下您复制的项目的 ID 也很好(如果它来自同一个菜单,那就更好了),因为我们将在下一步中使用它。
Now go to wp_postmeta
and search on the post_id
field for the item we just copied. This will bring up all of the fields that need to be filled in to get the info for our new menu item. Using phpMyAdmin copy each of those entries and change as needed. _menu_item_menu_item_parent
, _menu_item_target
, and _menu_item_classes
are the fields that will most likely need changing. And make sure you're putting the ID of your new item (9179) in _menu_item_object_id
.
现在转到wp_postmeta
并搜索post_id
我们刚刚复制的项目的字段。这将显示需要填写的所有字段以获取我们新菜单项的信息。使用 phpMyAdmin 复制每个条目并根据需要进行更改。_menu_item_menu_item_parent
、_menu_item_target
和_menu_item_classes
是最有可能需要更改的字段。并确保将新项目的 ID (9179) 放入_menu_item_object_id
.
After those are all created we can now tie that menu item to our menu. We need to get the term_taxonomy_id
from wp_term_taxonomy
. Just search term_id
using the ID from the first step, 33 for me. The term_taxonomy_id
happens to be 33 for me as well. No we need to insert a new row into wp_term_relationships
. object_id
will be your post id (9179) and term_taxonomy_id
is what we just looked up (33).
在所有这些都创建之后,我们现在可以将该菜单项绑定到我们的菜单。我们需要term_taxonomy_id
从wp_term_taxonomy
. 只需term_id
使用第一步中的 ID 进行搜索,对我来说是 33。该term_taxonomy_id
恰好是33对我来说也是如此。不,我们需要在wp_term_relationships
. object_id
将是您的帖子 ID (9179),term_taxonomy_id
也是我们刚刚查找的 (33)。
Now your new item should be in your menu.
现在您的新项目应该在您的菜单中。
回答by Eren
Each menu item are saved in posts table and menu hierarchy/options/urls etc. belonging to these items are stored in postmeta table. In postmeta table you can see post_id column belonging to posts table items.
每个菜单项都保存在帖子表中,属于这些项目的菜单层次结构/选项/网址等存储在 postmeta 表中。在 postmeta 表中,您可以看到属于帖子表项的 post_id 列。
回答by Enkode
Here are the SQL scripts I used:
以下是我使用的 SQL 脚本:
Get the menus from the wp_term table:
从 wp_term 表中获取菜单:
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'
Use the term_id to get get all of the menu titles / links from all the other connected tables. In my opinion this is a terrible relational database. Just replace the tt.term_id with yours from the query above, below is 11.
使用 term_id 从所有其他连接的表中获取所有菜单标题/链接。在我看来,这是一个糟糕的关系数据库。只需用上面查询中的 tt.term_id 替换 tt.term_id,下面是 11。
SELECT p.post_title, p.post_name, p.menu_order, pm.meta_value 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 INNER JOIN wp_postmeta AS pm ON p.Id = pm.post_id WHERE p.post_type = 'nav_menu_item' AND tt.term_id = 11 AND pm.meta_key = '_menu_item_url'
回答by sujit dwivedi
$postId = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM `wp_postmeta` WHERE meta_key='_menu_item_object_id' AND `meta_value`='$id'"));
$postIdc = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM `wp_postmeta` WHERE meta_key='_menu_item_object_id' AND `meta_value`='$a[1]'"));
$sql2 = "SELECT * FROM `wp_postmeta` WHERE meta_key='_menu_item_menu_item_parent' AND `meta_value`='$postId'";
$sql2c = "SELECT * FROM `wp_postmeta` WHERE meta_key='_menu_item_menu_item_parent' AND `meta_value`='$postIdc'";