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

Filtering results by category
In order to filter search results by category, use the following code: $url = get_bloginfo('url'); $url = esc_attr(add_query_arg(array('cat' => '10',…
Results are in strange order
If best results don’t come up first and changing weighting settings doesn’t seem to make any difference, there couple of…

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