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

Ordering search results by date
I’m building a directory and would like the oldest posts to automatically display first in the search results, is this…
PSA: New ransom scam in town
We were threatened with a new ransom extortion message. I haven’t seen this one before, looks like it’s new but…

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