Forum Replies Created

Viewing 1 replies (of 1 total)
  • I’ve been looking into this myself and I think I have a good grasp on the menues now. This post is fairly old, but someone might find this useful… It’s not a guide on how to build menues etc, I’m merely trying to share my findings of the construction.

    First off, to find the menues you have to find the taxonomy ids.

    SELECT *
    FROM wp_term_taxonomy tt
    INNER JOIN wp_terms t ON tt.term_id = t.term_id
    WHERE tt.taxonomy = ‘nav_menu’;

    There you should find the menu names and their ids. In this example, my menu is called ‘Main menu’ and has term_id 8.

    Secondly, to find all related menu items we turn to wp_term_relationships:

    SELECT *
    FROM wp_term_relationships tr
    WHERE tr.term_taxonomy_id = 8; # 8 would be the menu in this example.

    The object_ids returned represent the posts that are used for menu items. Ie, wp_term_relationships.object_id => wp_posts.ID.

    To get the structure, look in wp_post_meta. You’ll find the data parentid for each item by this query:

    SELECT *
    FROM wp_postmeta pm
    WHERE post_id = 77; # 77 being the first post returned from wp_term_relationships. In this example, this is the result:

    meta_id, post_id, meta_key, wp_postmeta, meta_value
    ‘499’, ’77’, ‘_menu_item_type’, ‘custom’
    ‘500’, ’77’, ‘_menu_item_menu_item_parent’, ‘0’
    ‘501’, ’77’, ‘_menu_item_object_id’, ’77’
    ‘502’, ’77’, ‘_menu_item_object’, ‘custom’
    ‘503’, ’77’, ‘_menu_item_target’, ”
    ‘504’, ’77’, ‘_menu_item_classes’, ‘a:1:{i:0;s:0:””;}’
    ‘505’, ’77’, ‘_menu_item_xfn’, ”
    ‘506’, ’77’, ‘_menu_item_url’, ‘https://localhost/mysite/’

    Use meta_key = ‘_menu_item_menu_item_parent’ (and wp_posts.menu_order) to get the menu structure.

    Hope this helps someone.

Viewing 1 replies (of 1 total)