How to duplicate custom menu settings to export to another site

I’m trying to write a routine that will pull items from the wp_options table in order to transport them to another site.

The problem I have is that if the source site has custom menus, I’d like to bring those along as well. What table records are referenced for custom menus?

Read More

I see at least these three in wp_options:

widget_nav_menu
theme_mods_myTheme
myTheme_menus_created

Related posts

Leave a Reply

1 comment

  1. 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.