How to duplicate custom menu settings to export to another site

Menus aren’t stored in options. They are linked quite complicatedly so through various other tables.

$wpdb->get_results(sprintf("
        select tr.object_id from wp_terms t 
        left join wp_term_taxonomy tt on t.term_id = tt.term_id
        left join wp_term_relationships tr on tt.term_taxonomy_id = tr.term_taxonomy_id
        left join wp_posts p on p.ID=tr.object_id
        left join wp_postmeta m on m.post_id=tr.object_id
        where t.slug ='%s' and tt.taxonomy='nav_menu' group by(ID)
        order by p.menu_order asc LIMIT 200;
        ",$menu));

where $menu is the slug of the menu such as main, footer or whatever you may have called it.

The query outlines the relationships that you have to account for.

Leave a Comment