最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

multisite - Display menu locations in all sites of a multi site

programmeradmin4浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论