Skip to main contentSkip to footer

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

Direct access to the query engine

Relevanssi can’t be used in any situation, because it checks the presence of search with the is_search() function. This causes some unfortunate limitations and reduces the general usability of the plugin. You can, however, access the query engine directly. There’s a function called relevanssi_do_query(), which can be used to do search queries…

How to display relevancy score

Relevanssi stores the relevance score it uses to sort results in the $post variable. Just add something like <?php echo “Score: $post->relevance_score”; ?> to your search results template to display the relevance score….

WooCommerce: Return only exact matches for SKU searches

…_sku custom field (because otherwise, SKU search will not find anything), and the search query must match the SKU exactly. Add this code to your site: add_filter( ‘relevanssi_hits_filter’, ‘rlv_sku_exact_match’ ); function rlv_sku_exact_match( $hits ) { global $wpdb; $post_ids = $wpdb->get_col( $wpdb->prepare( “SELECT post_id FROM $wpdb->postmeta WHERE meta_key = ‘_sku’ AND……)[‘object’]; return in_array( $hit_object->ID, $post_ids, false ); } ); return $hits; } Any searches that match an SKU in the database should only return the product matching the SKU. If you index product variation SKUs for the main product, the function above won’t work. When searching for product variation SKUs,…This little filter function works on relevanssi_hits_filter. When a search query is made that matches an SKU (or any other custom field, but SKUs are the most likely scenario here), only results that match the SKU will be returned. For this to work, Relevanssi must be set to index 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