Skip to main contentSkip to footer

Menu problems in multisite search

Sometimes multisite searches cause problems in navigation menus. This is caused by pages from another subsite going into the page cache, and then replacing a page in the navigation menu with the same page ID.

If you’re having this problem, adding the following code to the theme functions.php should solve the issue.

add_action( 'wp_head', 'rlv_uncache_menu_posts', 99 );
function rlv_uncache_menu_posts() { 
    if ( is_search() ) { 
        global $wpdb; 
        $ids = $wpdb->get_col("SELECT meta.meta_value FROM $wpdb->posts as posts, $wpdb->postmeta as meta 
            WHERE posts.ID = meta.post_id AND posts.post_type = 'nav_menu_item' 
            AND meta.meta_key = '_menu_item_object_id'"); 
        if ( is_array( $ids ) ) { 
            foreach ( $ids as $id ) { 
                clean_post_cache( $id ); 
            } 
        } 
    } 
}

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

ThemeCo
ThemeCo themes use custom codes for dynamic content. Those are not usual shortcodes, and Relevanssi won’t expand them automatically. In…
Using multiple custom taxonomies

Usually, WordPress supports one category, one tag and one taxonomy in the search, if you use the query variables to set the taxonomies. You can enter multiple taxonomies as parameters to the query, but only the first one is used. If you want to have multiple taxonomies involved, you need…

User Access Manager
Relevanssi has a conflict with User Access Manager plugin. Both plugins attach to the same `the_posts` filter hook with the…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed