I have a multi site network setup. I am trying to list all menu locations for all sites, so I tried the following code:
global $wpdb;
$table_blogs = $wpdb->prefix . 'blogs';
$blogs_results = $wpdb->get_results("SELECT * FROM $table_blogs");
foreach ($blogs_results as $blog) {
// Switch to a blog (or network site)
switch_to_blog($blog->blog_id);
// The following line of code is not working as expected ...
// ... It only returns the list of menu locations for the first site in the network ...
// ... and not for the active site
$menu_locations = get_registered_nav_menus();
// Retore current blog
restore_current_blog();
}
I thought the above code will return the list of menu locations for each site in the network. However, as you can see in the comment above, the get_registered_nav_menus()
function is only returning the list of menu locations for the first site that is registered in the network, and switching the blog is not changing the perspective to allow the list of locations for the other sites in the network, and it is returning an empty list instead. How can I return the list of locations for each of the sites in the network?
Thanks.