Continue reading Setting post_type to page doesn’t work

Setting post_type to page doesn’t work

For some reason setting the post_type query variable to page doesn’t have the desired effect. Other post types (post, custom post types) work, but page doesn’t do anything. This is not a Relevanssi bug, but a WordPress feature (see this trac ticket). If the user inputs a bad value to the post_type query variable, WordPress…

Read more Setting post_type to page doesn’t work 0 Comment on Setting post_type to page doesn’t work
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 Using Relevanssi without a search term

Using Relevanssi without a search term

…} return $search_ok; } This function will trigger Relevanssi, when the query var price appears in the query. Of course, without a search term, Relevanssi will find nothing. So, you need another function attached to relevanssi_hits_filter. It needs to have something like this: add_filter( ‘relevanssi_hits_filter’, ‘rlv_hits_filter’ ); function rlv_hits_filter( $hits……is, Relevanssi doesn’t trigger without a search term. To fix that, you need to use a new filter hook relevanssi_search_ok. Add this code to your site: add_filter( ‘relevanssi_search_ok’, ‘search_trigger’ ); function search_trigger( $search_ok ) { global $wp_query; if ( ! empty( $wp_query->query_vars[ ‘price’ ] ) ) { $search_ok = true;…Deprecated: Relevanssi has long supported searching without a search term. These instructions are not necessary. 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…

Read more Using Relevanssi without a search term 42 Comments on Using Relevanssi without a search term
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 Custom weighing with relevanssi_match and relevanssi_results

Custom weighing with relevanssi_match and relevanssi_results

…’,’, array_keys( $results ) ) . “)” ); $child_posts = array_flip( $child_posts ); array_walk( $results, function( &$weight, $post_id ) use ( $child_posts ) { if ( ! isset( $child_posts[ $post_id ] ) ) { // Not a child post. $weight *= 10; } } ); return $results; } ); Weight…posts: add_filter( ‘relevanssi_results’, ‘rlv_dynamic_time_weights’ ); function rlv_dynamic_time_weights( $results ) { array_walk( $results, function( &$weight, $post_id ) { $now = date_create( ‘now’ ); $post_date = date_create( get_the_time( ‘Y-m-d’, $post_id ) ); $diff_days = $now->diff( $post_date, true )->format( ‘%a’ ); if ( $diff_days < 1 ) { $diff_days = 1; } $multiplier……) { array_walk( $results, function( &$weight, $post_id ) { if ( ‘user’ === relevanssi_get_post_type( $post_id ) ) { $weight *= 2; } } ); return $results; } Weight from taxonomy terms Here’s how you can add extra weight to posts that have a particular taxonomy term. Just add this function…

Read more Custom weighing with relevanssi_match and relevanssi_results 64 Comments on Custom weighing with relevanssi_match and relevanssi_results
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 Search results breakdown by type

Search results breakdown by type

Do you want to have a breakdown of search results by post type? This could be used for example to show a list of post types like books, movies, or albums on a review site, and make them links to limit the search results to that post type. This is fairly easy to do with…

Read more Search results breakdown by type 51 Comments on Search results breakdown by type
Continue reading Multisite searches

Multisite searches

Multisite search only works in Relevanssi Premium. Free Relevanssi can be installed in multisite environments, but it cannot search across sites. Relevanssi Premium can only support multisite searching across sites in the same multisite network. Relevanssi can’t search across multiple sites that are not in the same multisite installation. Cloud-based……other hand, you can adjust the settings for each blog. Enabling the multisite search There are several ways to enable multisite searching. If you want all searches to be multisite searches, you can enable multisite searching from the Relevanssi searching settings. If you want only some searches to be multisite…to what multisite searching can do. There’s limited access to search parameters. You can use post_type, operator, meta_query, include_attachments and orderby. Taxonomy terms from subsites can cause problems. Searching for taxonomy terms in taxonomies that exist in the current site works: for example searching for categories from different sites works,…

Read more Multisite searches 144 Comments on Multisite searches
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