Posted on

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 ); 
            } 
        } 
    } 
}

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

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