Continue reading How to block searches without a search term

How to block searches without a search term

By default, Relevanssi returns all posts when searching without a search term. That’s the default WordPress behaviour. Sometimes it may not be the wanted behaviour. One reason is performance: returning all results can be very slow. To stop Relevanssi from running when there’s no search term, add this to your site: This little function will…

Read more How to block searches without a search term 2 Comments on How to block searches without a search term
Continue reading Gutenberg Full Site Editing

Gutenberg Full Site Editing

…core WP excerpt block does not allow Relevanssi highlights in excerpts. It will display Relevanssi excerpts (restricted to the excerpt length in the block settings – make sure the setting in the block is higher than the Relevanssi excerpt length setting), but no highlights will be visible because all the…excerpts are passed through wp_trim_words() which removes HTML tags. This function can be used to overcome this limitation: add_filter( ‘wp_trim_words’, function( $text, $num_words, $more, $original_text ) { global $post; if ( isset( $post->relevance_score ) ) { return $post->post_excerpt; } return $text; }, 10, 4 ); If the post has the……relevance_score attribute set – which should only happen within a search context – this function will cause the wp_trim_words() to return the original post excerpt. With Max Mega Menu, the function above will add the excerpts to the menu items. You can avoid that: add_filter( ‘wp_trim_words’, function( $text, $num_words, $more,…

Read more Gutenberg Full Site Editing 2 Comments on Gutenberg Full Site Editing
Continue reading Elementor

Elementor

…a Query ID in the Elementor settings and then add this to your site: add_action( ‘elementor/query/YOUR_QUERY_ID’, function( $query ) { $query->set( ‘relevanssi’, true ); } ); This will make that specific query use Relevanssi. Using Relevanssi with Elementor Live Results Elementor has a feature for custom Query Filters. These can……be used to connect Relevanssi with the Elementor Live Results and the Elementor Search Widget. First, you need to add this function to your site: function my_relevanssi_results( $query ) { $query->set( ‘relevanssi’, true ); $query->set( ‘orderby’, ‘relevance’ ); } add_action( ‘elementor/query/my_relevanssi_results’, ‘my_relevanssi_results’ ); Then, follow these instructions from Elementor: Assuming…Elementor is a popular page builder. It works rather well with Relevanssi, most of the time. Check for e_search_props If the search results come back empty or are restricted to a specific post type, it’s possible Elementor is restricting them. Elementor can hide the query parameters to a single query…

Read more Elementor 4 Comments on Elementor
Continue reading Premium 2.1.1 / Free 4.0.5

Premium 2.1.1 / Free 4.0.5

…Relevanssi Premium release is now also automatically tested. This should make sure any modifications to the code don’t break any old features. The test suite is still something of a work-in-progress. It’s available on Github if you want to take a look at it. More tests will be added as……we come up with things to test, and whenever there’s a problem, we’ll add a test for it to make sure it won’t happen again. Another good reason to bump up the version number a bit is the addition of new attachment types. Relevanssi can now handle the most common……document types. Update 27.3.2018: Well, looks like automated testing isn’t a perfect solution. Some overzealous security measures made the Network options page break a bit. Version 2.1.1 fixes that. (Premium only.) Attachment indexing has been extended to many more document types: now it should be able to handle most document…

Read more Premium 2.1.1 / Free 4.0.5 0 Comment on Premium 2.1.1 / Free 4.0.5
Continue reading Free 3.0

Free 3.0

…$wp_query before it is passed to Relevanssi. New filter: relevanssi_search_ok lets you adjust when search is enabled. New filter: relevanssi_pre_excerpt_content lets you adjust post content before excerpt creation. New filter: relevanssi_excerpt_content lets you adjust post content before excerpt creation, but after the_content. New filter: relevanssi_ellipsis lets you change the default……‘…’ in excerpts to something else. New filter: relevanssi_do_not_index is given a post ID and expects a boolean in return: should this post be indexed or not? New filter: relevanssi_match lets you meddle with the matching engine. New filter: relevanssi_results filters the result set from the search. New filter: relevanssi_content_to_index……need Relevanssi Premium, which does it better anyway. Relevanssi can handle certain whitespace characters better in indexing. Apostrophes are now replaced with whitespace instead of being removed. Relevanssi now shows correct number of results when posts_per_page is set to -1. Fuzzy search didn’t always activate when it should, if all…

Read more Free 3.0 32 Comments on Free 3.0
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……$wp_query-&>query_vars[‘tax_query’] ) || isset( $wp_query->query_vars[‘meta_query’] ) ) { $search_ok = true; } return $search_ok; } Then in the hits filter, run a similar check, turn nopaging on and return the results of get_posts() with my modified query_vars. Add this to your site: add_filter( ‘relevanssi_hits_filter’, ‘rlv_hits_filter’ ); /** * return results……when there are active filters but no search term * @param array $hits $hits[0] is a list of matched WP_Post objects * $hits[1] is the search term if any * @return array $hits */ function rlv_hits_filter( $hits ) { global $wp_query; if ( ! $hits[1] && isset( $wp_query->query_vars[‘tax_query’] ) ||…

Read more Using Relevanssi without a search term 42 Comments on Using Relevanssi without a search term