Continue reading Scroll result page to the search term

Scroll result page to the search term

Relevanssi can highlight search terms on the posts. But how about scrolling the page to show the location where the search results are? That is also possible. It requires a bit of JavaScript on the post page. This script needs to run on the post page: <script> jQuery(document).ready(function($) { $.extend($.expr[":"], { "containsNC": function(elem, i, match,…

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

Category filter for search results pages

Sometimes it’s nice to have a category filter on the search results pages: a simple dropdown where you can choose the category you want to show. It’s easy to create one using wp_dropdown_categories(), but on a search results page that’s slightly problematic, as it’ll include all categories, not just those included in the search results.…

Read more Category filter for search results pages 16 Comments on Category filter for search results pages
Continue reading Relevanssi and Modernize

Relevanssi and Modernize

Modernize is a neat Premium theme that has a problem with Relevanssi. Relevanssi highlighting can cause problems on Modernize search results pages, with results getting wrong background color. This problem is caused by the way Modernize truncates excerpts to certain length, set in the Modernize settings. It doesn’t care about HTML tags, so Modernize may…

Read more Relevanssi and Modernize 0 Comment on Relevanssi and Modernize
Continue reading Ordering search results by date

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 possible? I found out how to add a link that the user can click to sort the results but would like an automatic solution. Can you provide code that can be added to the functions.php…

Read more Ordering search results by date 3 Comments on Ordering search results by date
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: if (function_exists(’relevanssi_related’)) relevanssi_related(get_search_query(), ‘<h3>Related Searches:</h3><ul><li>’,…

Read more Related searches feature 19 Comments on Related searches feature
Continue reading Taxonomy page search

Taxonomy page 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 in the options page. There’s also the option to choose which taxonomies are included. Currently the title of the taxonomy is…

Read more Taxonomy page search 41 Comments on Taxonomy page 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: $myquery = "&posts_per_page=5"; $myquery = $query_string.$myquery; query_posts($myquery); $myquery = "&posts_per_page=5"; $myquery = $query_string.$myquery; query_posts($myquery); Unfortunately, this breaks Relevanssi. Relevanssi hasn’t played nice with posts_per_page in any case, for some reasons I don’t really understand — this is legacy code from…

Read more Changing the number of search results displayed 47 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. <?php $cat = get_cat_name($wp_query->query_vars[‘cat’]); $s =…

Read more Category title in the search results page 1 Comment on Category title in the search results page
Continue reading User profile search

User profile search

Relevanssi Premium can search user profiles. So far the following data gets indexed from user profiles: first name, last name, display name and description. If you’re interested in having something else indexed, there’s an option in the options page. Because WordPress only handles posts in the search result pages, Relevanssi must make WordPress believe it’s…

Read more User profile search 69 Comments on User profile search