Continue reading Scroll result page to the search term

Scroll result page to the search term

…{ “containsNC”: function(elem, i, match, array) { return (elem.textContent || elem.innerText || “”).toLowerCase().indexOf((match[3] || “”).toLowerCase()) >= 0; } }); var mySearchString = getParams(“highlight”); var offsetToWord = $(“p:containsNC(‘” +mySearchString + “‘):first”).offset().top; $(“html, body”).animate({ scrollTop: offsetToWord }, 0); function getParams(param) { var vars = {}; window.location.href.replace( location.hash, ” ).replace( /[?&]+([^=&]+)=?([^&]*)?/gi, // regexp…

Read more Scroll result page to the search term 11 Comments on Scroll result page to the search term
Continue reading Category filter for search results pages

Category filter for search results pages

…included in the search results. So, here’s a two-part function that fixes that. First, we need a filter that processes the search results and gets a list of categories in the results. This filter runs very late on the relevanssi_hits_filter hook, so that it runs after other filters on the……in place, there’s instead a link that removes all category filters. function rlv_category_dropdown() { global $rlv_categories_present, $wp_query; if ( ! empty( $wp_query->query_vars[‘cat’] ) ) { $url = esc_url( remove_query_arg( ‘cat’ ) ); echo “<p><a href=’$url’>Remove category filter</a>.</p>”; } else { $select = “<select id=’rlv_cat’ name=’rlv_cat’><option value=”>Choose a category</option>”; foreach (……same hook: add_filter( ‘relevanssi_hits_filter’, ‘rlv_gather_categories’, 99 ); function rlv_gather_categories( $hits ) { global $rlv_categories_present; $rlv_categories_present = array(); foreach ( $hits[0] as $hit ) { $terms = get_the_terms( $hit->ID, ‘category’ ); if ( is_array( $terms ) ) { foreach ( $terms as $term ) { $rlv_categories_present[ $term->term_id ] = $term->name; }…

Read more Category filter for search results pages 33 Comments on Category filter for search results pages
Continue reading Filtering results by category

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’, ‘s’ => get_search_query()), $url)); echo "<a href=’$url’ rel=’nofollow’>Filter by category 10</a>";$url = get_bloginfo(‘url’); $url = esc_attr(add_query_arg(array(‘cat’ => ’10’, ‘s’ => get_search_query()), $url)); echo "<a href=’$url’ rel=’nofollow’>Filter by category 10</a>"; Put this in your search results…

Read more Filtering results by category 27 Comments on Filtering results by category
Continue reading Related searches feature

Related searches feature

John Blackbourn wrote a cool related searches feature for Relevanssi Premium. It’s included from version 1.7.4. In order to use the related searches, you must have search logging enabled and a good log of past searches. Then add the following code to your search results template in a suitable place: The first parameter is the…

Read more Related searches feature 21 Comments on Related searches feature
Continue reading Taxonomy archive search

Taxonomy archive search

This is a Premium feature and only applies when you index taxonomy terms. This does not apply in free Relevanssi. To include taxonomy pages (categories, tags, custom taxonomies) in the search, enable the option on the options page. There’s also the option to choose which taxonomies are included. By default……the post object created from the taxonomy page, $post->post_title contains the name of the taxonomy, $post->post_content has the description, $post->link has the permalink and $post->post_type will contain the name of the taxonomy. If you want to modify the post objects Relevanssi creates from the taxonomies, you can use the relevanssi_taxonomy_term_to_post filter….…empty terms (not linked to any posts) are excluded from the index. If you want to modify that, see relevanssi_hide_empty_terms. What is indexed? Currently, the title of the taxonomy is indexed with the description field. Indexing the other fields isn’t currently possible. Taxonomy pages should be automatically updated in the…

Read more Taxonomy archive search 49 Comments on Taxonomy archive search
Continue reading Changing the number of search results displayed

Changing the number of search results displayed

A standard way to change the number of search results displayed is something like this: Unfortunately, this breaks Relevanssi. Relevanssi hasn’t played nice with posts_per_page in any case, for some reason I don’t really understand — this is legacy code from the original wpSearch plugin. However, from Premium version 1.4.4 and free 2.9.2, you can…

Read more Changing the number of search results displayed 49 Comments on Changing the number of search results displayed
Continue reading Category title in the search results page

Category title in the search results page

If you’re using category restriction dropdown on your search form, here’s a bit of code that you can add to your search results template to show how many hits were found and what the category is. If no category was selected, this’ll just show how many hits were found.

Read more Category title in the search results page 1 Comment on Category title in the search results page