Continue reading Using multiple custom taxonomies

Using multiple custom taxonomies

Usually WordPress supports one category, one tag and one taxonomy in the search, if you use the query variables to set the taxonomies. You can enter multiple taxonomies as parameters to the query, but only the first one is used. If you want to have multiple taxonomies involved, you need to build a tax_query. The…

Read more Using multiple custom taxonomies 52 Comments on Using multiple custom taxonomies
Continue reading Which custom fields had the hit?

Which custom fields had the hit?

While the free version of Relevanssi will match search terms in custom field content, it doesn’t know which custom field had the matching content. Premium has that information and it can be made available. First, you need this in your functions.php: add_filter(’relevanssi_match’, ‘cfdetail’); function cfdetail($match) { global $customfield_data; $customfield_data[$match->doc] = $match->customfield_detail; return $match; }add_filter(‘relevanssi_match’, ‘cfdetail’);…

Read more Which custom fields had the hit? 10 Comments on Which custom fields had the hit?
Continue reading Using Relevanssi with WP e-Commerce

Using Relevanssi with WP e-Commerce

WP e-Commerce is a popular shopping cart plugin for WordPress. This code by Alexander Gieg, added to functions.php for example, makes Relevanssi work better with WP e-Commerce. add_filter(’relevanssi_excerpt_content’,’wpscproductexcerpt’,10,3); function wpscproductexcerpt($content, $post, $query) { if ( ‘wpsc-product’ == relevanssi_get_post_type($post->ID) ) { $content = $post->post_content . ( !empty($post->post_excerpt) ? " $post->post_excerpt" : ” ); if ( ‘on’…

Read more Using Relevanssi with WP e-Commerce 14 Comments on Using Relevanssi with WP e-Commerce
Continue reading Relevanssi_results filter

Relevanssi_results filter

From 2.9.13 and Premium 1.7.6 there’s a new filter, relevanssi_results. This filter is given an array containing the search results in (post ID, weight) format. The filter expects to get the same thing back. This filter can be used for processing the hits somehow, modifying the weights and whatever you can come up with. I…

Read more Relevanssi_results filter 0 Comment on Relevanssi_results filter
Continue reading Using Relevanssi without a search term

Using Relevanssi without a search term

Version 1.7.3 introduces the possibility to use Relevanssi without a search term. This is useful when you have extra query arguments that can be used to narrow the search, but which would be useful without a search term present. This was originally implented for a restaurant search, where the users can search for restaurants based…

Read more Using Relevanssi without a search term 42 Comments on Using Relevanssi without a search term
Continue reading Separating posts by post type

Separating posts by post type

Using the relevanssi_hits_filter, it’s easy to separate the search results by post type. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 add_filter(’relevanssi_hits_filter’, ‘separate_result_types’); function separate_result_types($hits) { $types = array(); $types[’mycustomtypethatgoesfirst’] = array(); $types[’thesecondmostimportanttype’] = array(); $types[’post’] = array(); $types[’page’] = array();   //…

Read more Separating posts by post type 28 Comments on Separating posts by post type
Continue reading Relevanssi_post_ok filter

Relevanssi_post_ok filter

Versions 2.9.8 (free) and 1.5.13 (premium) added a new filter, relevanssi_post_ok, which can be used to add support for membership plugins where there is a need to restrict certain posts from certain users. By default, this filter calls relevanssi_default_post_ok(), which has built-in support for private posts, Role-Scoper and s2member. Add your own function, if you…

Read more Relevanssi_post_ok filter 3 Comments on Relevanssi_post_ok filter
Continue reading Modify excerpts with relevanssi_excerpt_content

Modify excerpts with relevanssi_excerpt_content

From free 2.9.1 and Premium 1.5.8, there’s a new filter that makes modifying the excerpts easier. The relevanssi_excerpt_content filter is run after the post content is run through the the_content filter and before any other cleanup is done. This is a good point to insert for example custom field content. The filter hook passes three…

Read more Modify excerpts with relevanssi_excerpt_content 33 Comments on Modify excerpts with relevanssi_excerpt_content
Continue reading Disabling title or content indexing

Disabling title or content indexing

If you want to prevent the indexing titles or post content for some reason, Premium has couple of useful filters starting from version 1.5.5. The filters are called┬árelevanssi_index_content and┬árelevanssi_index_titles. These are simple true/false filters, so if you want to activate the filter, add a function that returns false, like this: add_filter(‘relevanssi_index_content’, ‘contentoff’); function contentoff() {…

Read more Disabling title or content indexing 56 Comments on Disabling title or content indexing
Continue reading Making post body not count

Making post body not count

This function will re-calculate the post weights so that post body has no significance. Only titles, excerpts, categories and so on will effect the search results. add_filter(‘relevanssi_match’, ‘no_post_body’); function no_post_body($match) { $title_boost = get_option(‘relevanssi_title_boost’); $tag_boost = get_option(‘relevanssi_tag_boost’); $link_boost = get_option(‘relevanssi_link_boost’); $comment_boost = get_option(‘relevanssi_comment_boost’); $idf = $match->weight / $match->tf; $match->tf = $match->title * $title_boost + $match->comment…

Read more Making post body not count 0 Comment on Making post body not count