### Implement Relevanssi Shortcodes and Programmatic Forms Source: https://context7.com/msaari/relevanssi/llms.txt Use these shortcodes to embed search forms and links in content. The programmatic example demonstrates how to generate a search form using PHP attributes. ```php 'post,page', 'dropdown' => 'category', ); echo relevanssi_search_form( $atts ); // Filter the search form output add_filter( 'relevanssi_search_form', function( $form, $atts ) { // Modify form HTML return str_replace( '', '', $form ); }, 10, 2 ); ``` -------------------------------- ### Remove notices about duplicated database columns Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Notices about duplicated database columns during plugin installation have been removed. This cleans up the installation process and avoids unnecessary warnings. ```php Remove notices about duplicated database columns when installing the plugin. ``` -------------------------------- ### Enable plugin uninstallation Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The Relevanssi plugin can now be uninstalled. This provides a standard way to remove the plugin from a WordPress installation. ```php The plugin can now be uninstalled. ``` -------------------------------- ### Add documentation to WordPress contextual help Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Documentation is now available within the WordPress contextual help section. Users can access this by clicking 'Help' in the top right corner of the screen. ```php There's documentation in the WordPress contextual help: just click Help on the top right corner. ``` -------------------------------- ### Build and Manage Search Index Source: https://context7.com/msaari/relevanssi/llms.txt Functions for managing the Relevanssi search index. `relevanssi_build_index()` creates or rebuilds the entire index, with options to extend it by indexing only missing posts. `relevanssi_index_doc()` indexes individual posts, and `relevanssi_remove_doc()` removes a post from the index. `relevanssi_truncate_index()` clears the entire index, and `relevanssi_count_total_posts()` and `relevanssi_count_missing_posts()` provide index statistics. ```php Did you mean: '; $post = '?

'; $max_results = 5; // Only show suggestions if results are <= this number // Echo the suggestion directly relevanssi_didyoumean( $query, $pre, $post, $max_results, true ); // Or get the suggestion as a string $suggestion_html = relevanssi_didyoumean( $query, $pre, $post, $max_results, false ); if ( $suggestion_html ) { echo $suggestion_html; } // Generate just the corrected query string $corrected_query = relevanssi_simple_generate_suggestion( $query ); if ( $corrected_query && $corrected_query !== $query ) { $url = add_query_arg( 's', urlencode( $corrected_query ), home_url( '/' ) ); echo "$corrected_query"; } // Filter the suggestion URL add_filter( 'relevanssi_didyoumean_url', function( $url, $query, $suggestion ) { return add_query_arg( 'source', 'didyoumean', $url ); }, 10, 3 ); ``` -------------------------------- ### Relevanssi WPFD File Content Indexing Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Improved WPFD file content indexing support. Relevanssi indexing now occurs after WPFD indexing is completed for better integration. ```php WPFD file content indexing ``` -------------------------------- ### Improve Groups and Simple Membership support Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Support for Groups and Simple Membership plugins has been improved. This ensures better integration and compatibility with these membership and user management plugins. ```php Groups and Simple Membership support has been improved. ``` -------------------------------- ### Automatically trim Relevanssi logs Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Logs can now be automatically trimmed to save disk space. Old log entries are removed to manage storage efficiently. ```php Logs can be automatically trimmed. Old log entries are removed to save space. ``` -------------------------------- ### Ensure all posts are indexed at once Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Relevanssi previously did not index all posts in a single operation. It now indexes all posts at once, improving the efficiency of the indexing process. ```php Relevanssi didn't index all posts with one go. It does now. ``` -------------------------------- ### Adding Synonyms Source: https://context7.com/msaari/relevanssi/llms.txt Functions to manage and apply synonym expansion to search queries. ```APIDOC ## PHP Function: relevanssi_add_synonyms ### Description Expands a search query by replacing or adding terms based on configured synonyms. ### Parameters - **query** (string) - Required - The search query to expand. ### Configuration - Synonyms are stored in the 'relevanssi_synonyms' option as a serialized array keyed by language code (e.g., 'en_US'), containing strings in the format 'word=synonym;another=replacement'. ``` -------------------------------- ### Did You Mean Suggestions Source: https://context7.com/msaari/relevanssi/llms.txt Functions to generate and display Google-style spelling suggestions based on search logs. ```APIDOC ## PHP Function: relevanssi_didyoumean ### Description Displays or returns spelling suggestions for a search query based on successful searches stored in the log. ### Parameters - **query** (string) - Required - The search query to check. - **pre** (string) - Required - HTML to prepend to the suggestion. - **post** (string) - Required - HTML to append to the suggestion. - **max_results** (int) - Required - Maximum number of results allowed to trigger a suggestion. - **echo** (bool) - Required - Whether to echo the result or return it as a string. ## PHP Function: relevanssi_simple_generate_suggestion ### Description Generates a corrected query string based on spelling suggestions. ### Parameters - **query** (string) - Required - The original search query. ``` -------------------------------- ### Create Custom Excerpts with Highlighting Source: https://context7.com/msaari/relevanssi/llms.txt Generate custom excerpts with search term highlighting using `relevanssi_do_excerpt()`. This function takes the post object, search query, excerpt length, and type ('chars' or 'words'). You can customize highlighting tags and ellipsis using filters. The code also shows how to automatically add excerpts to the post object and highlight post titles. ```php %s'; }); // Filter the ellipsis used in excerpts add_filter( 'relevanssi_ellipsis', function( $ellipsis ) { return ' [...]'; }); // Add excerpt to post object during search (usually automatic) relevanssi_add_excerpt( $post, $query ); echo $post->post_excerpt; // Contains highlighted excerpt // Highlight post title relevanssi_highlight_post_title( $post, $query ); echo $post->post_title; // Contains highlighted title ``` -------------------------------- ### Improve indexing process Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The indexing process has been improved to eliminate the need for repeated 'Continue indexing' clicks. This streamlines the indexing workflow. ```php Improved indexing: no more clicking "Continue indexing" again and again! ``` -------------------------------- ### Set SQL_BIG_SELECTS during Indexing with relevanssi_pre_indexing_query Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Use this action hook to set the SQL_BIG_SELECTS option to 1 if your indexing process requires it. This can help prevent errors with large select queries during indexing. ```php add_action( 'relevanssi_pre_indexing_query', 'my_relevanssi_set_big_selects' ); function my_relevanssi_set_big_selects() { global $wpdb; $wpdb->query( 'SET OPTION SQL_BIG_SELECTS=1' ); } ``` -------------------------------- ### Optimize excerpt building in Relevanssi Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The `relevanssi_optimize_excerpts` filter can be used to speed up the excerpt building process. If this filter returns `true`, excerpt generation will be optimized. ```php New filter: `relevanssi_optimize_excerpts` makes excerpt-building faster, if you make the filter return `true`. ``` -------------------------------- ### Customize Indexing for Custom Fields and Content Source: https://context7.com/msaari/relevanssi/llms.txt Hooks to manage custom field indexing and manipulate content before it is saved to the index. Use these to include metadata or strip unwanted patterns. ```php ID, 'related_products', true ); if ( $related ) { $content .= ' ' . implode( ' ', $related ); } return $content; }, 10, 2 ); // Filter post content before indexing add_filter( 'relevanssi_post_content', function( $content, $post ) { // Remove certain patterns $content = preg_replace( '/\[ad\].*?\[\/ad\]/s', '', $content ); return $content; }, 10, 2 ); // Filter which custom fields to index per post add_filter( 'relevanssi_index_custom_fields', function( $fields, $post_id ) { $post_type = get_post_type( $post_id ); if ( $post_type === 'product' ) { $fields[] = '_price'; $fields[] = '_sku'; } return $fields; }, 10, 2 ); ``` -------------------------------- ### Support Simple Membership plugin for post access restriction Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Relevanssi now automatically supports the Simple Membership plugin to restrict access to posts. This integration ensures that restricted posts are handled correctly by Relevanssi. ```php Simple Membership plugin is now supported automatically to restrict access to posts. ``` -------------------------------- ### Block Easy Digital Downloads shortcodes during indexing Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Relevanssi now automatically blocks Easy Digital Downloads shortcodes when indexing content. This improves compatibility with EDD and prevents potential issues with shortcode expansion during the indexing process. ```php Relevanssi now blocks Easy Digital Downloads shortcodes when indexing to improve compatibility with EDD. ``` -------------------------------- ### Relevanssi Nav Menu Item Indexing Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Indexing of `nav_menu_item` posts is now stopped earlier in the process to avoid potential problems with large menus. ```php `nav_menu_item` posts ``` -------------------------------- ### Rewrite settings pages Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The settings pages for Relevanssi have been completely rewritten. This likely includes UI/UX improvements and better organization of settings. ```php Settings pages have been completely rewritten. ``` -------------------------------- ### Log Search Queries and Manage Index Data Source: https://context7.com/msaari/relevanssi/llms.txt Use these functions to manually log search queries, retrieve common words from the index for analysis, and update the document count. The log table includes fields for query, hits, timestamp, user ID, IP, and session ID. ```php 1, 'brown' => 1, 'fox' => 1, 'jumps' => 1, 'over' => 1, 'lazy' => 1, 'dog' => 1 ) // Tokenize without removing stopwords $tokens = relevanssi_tokenize( $text, false, -1, 'indexing' ); // Tokenize an array of strings $strings = array( 'Hello world', 'Goodbye world' ); $tokens = relevanssi_tokenize( $strings, true, 3, 'indexing' ); // Returns combined tokens from all strings // Filter punctuation handling add_filter( 'relevanssi_punctuation_filter', function( $replacements ) { $replacements['@'] = ''; // Remove @ symbols return $replacements; }); // Filter to customize tokenization add_filter( 'relevanssi_indexing_tokens', function( $tokens, $context ) { // Modify tokens before indexing unset( $tokens['unwanted'] ); return $tokens; }, 10, 2 ); ``` -------------------------------- ### Modify permalinks with highlight parameter Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Highlighting in documents now requires a `highlight` query parameter for reliability and to bypass caching. Use `relevanssi_get_permalink()` to generate permalinks with this parameter on search results templates. ```php Highlighting in documents is changed: it now requires a `highlight` query parameter. This helps getting pass caching and makes the highlighting more reliable. To get the query parameter active, use `relevanssi_get_permalink()` to print out the permalinks on the search results templates. ``` -------------------------------- ### Relevanssi Home Page URL Fix Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt A fix prevents Relevanssi from adding the `highlight` parameter to home page URLs when it should not. ```php `highlight` parameter to home page URLs ``` -------------------------------- ### Block autoembed procedure during excerpt building Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt To prevent performance issues, Relevanssi now blocks the autoembed procedure when building excerpts. This avoids long processing times caused by autoembed link discovery. ```php In some cases excerpt-building could take ages because of autoembed link discovery. Relevanssi now blocks the autoembed procedure in link-building. ``` -------------------------------- ### Relevanssi Oxygen Compatibility Upgrade Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Oxygen compatibility has been upgraded to support JSON data from Oxygen 4. Feedback from Oxygen users is encouraged for this early stage. ```json JSON data from Oxygen 4 ``` -------------------------------- ### Relevanssi Debugging Tab Information Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt New features in the Debugging tab allow users to view how posts appear in the database and see the MySQL max_allowed_packet size and the indexing query. ```text MySQL `max_allowed_packet` size indexing query ``` -------------------------------- ### Adjust content weight setting Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt A new setting allows users to adjust the content weight. This provides fine-grained control over how different content types contribute to search result relevance. ```php Finally a setting to adjust content weight! ``` -------------------------------- ### Relevanssi Taxonomy Query Handling Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Taxonomy query handling has been improved, particularly for Polylang users, to ensure Relevanssi respects language restrictions. ```php Polylang language restrictions ``` -------------------------------- ### Improve support for page builders Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Improvements have been made to enhance the support for various page builders. This ensures better compatibility and functionality when using Relevanssi with page builder content. ```php Improved the support for page builders. ``` -------------------------------- ### Improve Polylang setting Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Enhancements have been made to the Polylang setting within Relevanssi. This aims to improve the integration and functionality when using Relevanssi with the Polylang multilingual plugin. ```php Improvements to the Polylang setting. ``` -------------------------------- ### Use custom field content for excerpts Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Excerpts can now utilize content from custom fields. This allows for more dynamic and relevant excerpts based on specific field data. ```php Excerpts can use the custom field content. ``` -------------------------------- ### Relevanssi Tag and Category Weight Fix Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt A fix has been implemented for broken tag and category weight settings, ensuring accurate weighting for these taxonomies. ```php tag and category weight settings ``` -------------------------------- ### Run search again with modified parameters Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The `relevanssi_search_again` filter allows for running a search again if no results are found. It also enables modification of search parameters between search runs, providing a fallback mechanism. ```php New filter: `relevanssi_search_again` lets you run the search again if no results are found and to modify the parameters between search runs. ``` -------------------------------- ### Tokenizing Content Source: https://context7.com/msaari/relevanssi/llms.txt Functions to break text into searchable tokens with support for normalization and filtering. ```APIDOC ## PHP Function: relevanssi_tokenize ### Description Breaks a string or array of strings into searchable tokens, handling punctuation, stopwords, and character normalization. ### Parameters - **text** (string|array) - Required - The content to tokenize. - **remove_stopwords** (bool) - Required - Whether to filter out stopwords. - **min_word_length** (int) - Required - Minimum length for a token to be included. - **context** (string) - Required - The context of tokenization (e.g., 'indexing' or 'search_query'). ``` -------------------------------- ### Modify permalink generation for highlighting Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The `relevanssi_get_permalink` function has been updated to prevent adding the `highlight` parameter to URLs outside of search results pages or to front page links. This improves the reliability of highlighting and caching. ```php `relevanssi_get_permalink` doesn't add the `highlight` parameter to URLs outside search results pages anymore, and won't add the parameter to front page links either. ``` -------------------------------- ### Relevanssi Throttling with Date Sorting Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt When sorting results by post date in Relevanssi settings, throttling can now be enabled. This ensures the most recent posts are kept when throttling is active. ```php `orderby` to `post_date` ``` -------------------------------- ### Fix shortcode `searchform` in Relevanssi Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The `searchform` shortcode was not working properly. This has been fixed, ensuring that the `searchform` shortcode functions as expected within Relevanssi. ```php Fixed shortcode: `searchform` shortcode didn't work properly. ``` -------------------------------- ### Perform Search with WP_Query Source: https://context7.com/msaari/relevanssi/llms.txt Use the `relevanssi_do_query()` function to execute Relevanssi searches programmatically by passing a WP_Query object. This method is ideal for custom searches outside the main search template. You can configure search parameters like keywords, posts per page, pagination, post type, and search operator. ```php query_vars['s'] = 'wordpress development'; $search_query->query_vars['posts_per_page'] = 10; $search_query->query_vars['paged'] = 1; $search_query->query_vars['post_type'] = 'post'; // Optional: Set search operator (AND or OR) $search_query->query_vars['operator'] = 'AND'; // Run the Relevanssi search $posts = relevanssi_do_query( $search_query ); // Access results echo "Found " . $search_query->found_posts . " posts\n"; echo "Max pages: " . $search_query->max_num_pages . "\n"; // Loop through results foreach ( $posts as $post ) { echo "Title: " . $post->post_title . "\n"; echo "Relevance Score: " . $post->relevance_score . "\n"; echo "Excerpt: " . $post->post_excerpt . "\n"; } ``` -------------------------------- ### Remove legacy code Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Legacy code has been removed from the plugin. Users with versions older than 3.6.2.2 should update to that version first to ensure a smooth upgrade process. ```php Legacy code has been removed. If you have a version older than 3.6, update first to 3.6.2.2 to guarantee smooth upgrade process. ``` -------------------------------- ### Relevanssi Inner Block Filtering Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Relevanssi now recursively runs `relevanssi_block_to_render` and the CSS `relevanssi_noindex` filtering for inner blocks, improving handling of nested Gutenberg blocks. ```php relevanssi_block_to_render ``` ```php relevanssi_noindex ``` -------------------------------- ### Improve sorting speed in Relevanssi Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Sorting search results in Relevanssi is now up to 300 times faster. This significant performance improvement enhances the user experience, especially for large datasets. ```php Sorting search results is now up to 300 times faster than before. ``` -------------------------------- ### Relevanssi Support for JetSmartFilters Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Relevanssi now includes support for JetSmartFilters, improving compatibility with this filtering plugin. ```php JetSmartFilters ``` -------------------------------- ### Relevanssi Data Attributes Update Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Updates have been made to data attributes in highlighting and in-document highlighting to improve compatibility and prevent issues with certain elements. ```php data attributes ``` -------------------------------- ### Modify Options Page Capability with relevanssi_options_capability Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Use this filter to change the user capability required to access the Relevanssi options page. The default capability is 'manage_options'. ```php add_filter( 'relevanssi_options_capability', 'my_relevanssi_options_capability' ); function my_relevanssi_options_capability( $capability ) { return 'edit_posts'; } ``` -------------------------------- ### Relevanssi Event Calendar Compatibility Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Relevanssi now prevents interference in fringe cases, including event searches with The Event Calendar plugin. ```php The Event Calendar event search ``` -------------------------------- ### Relevanssi TablePress Shortcode Support Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Added support for TablePress `table_filter` shortcodes, allowing Relevanssi to index and search content within TablePress tables. ```php TablePress `table_filter` shortcodes ``` -------------------------------- ### Filter Search Results and Query Behavior Source: https://context7.com/msaari/relevanssi/llms.txt Hooks for modifying search hits, relevance weights, and query parameters. These filters allow for fine-grained control over what appears in search results. ```php title > 0 ) { $match->weight *= 2; } return $match; }, 10, 3 ); // Control which posts appear in results add_filter( 'relevanssi_post_ok', function( $post_ok, $post_id ) { // Check custom access rules if ( get_post_meta( $post_id, '_hidden', true ) ) { return false; } return $post_ok; }, 10, 2 ); // Block specific posts from indexing add_filter( 'relevanssi_do_not_index', function( $do_not_index, $post_id, $post ) { if ( $post->post_type === 'private_type' ) { return 'Private post type excluded'; } return $do_not_index; }, 10, 3 ); // Modify WP_Query before Relevanssi processes it add_filter( 'relevanssi_modify_wp_query', function( $query ) { // Add custom query modifications $query->set( 'post_status', 'publish' ); return $query; }); // Filter the search query WHERE clause add_filter( 'relevanssi_where', function( $where ) { global $wpdb; // Add custom restrictions $where .= " AND relevanssi.doc NOT IN (SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_excluded')"; return $where; }); ``` -------------------------------- ### Relevanssi Support for WooCommerce Attribute Lookup Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Added support for WooCommerce products attribute lookup table filtering, enhancing Relevanssi's compatibility with WooCommerce filtering methods. ```php WooCommerce products attribute lookup table filtering ``` -------------------------------- ### Relevanssi Highlight Parameter Fix Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt A minor fix addresses Relevanssi adding extra quotes around search terms in the `highlight` parameter and ensures quotes are added when the `sentence` query variable is used. ```php `highlight` parameter ``` -------------------------------- ### Handle problematic symbols in indexing Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The symbols © and ® previously caused indexing problems. They are now included in the default punctuation removal process to ensure smoother indexing. ```php © and ® symbols caused problems in indexing; they are now included in the default punctuation removal. ``` -------------------------------- ### Adjust Relevanssi options on update Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The `relevanssi_update_options` action hook allows for adjusting Relevanssi options immediately after the default options are set during an update. This is useful for custom configurations. ```php New action: `relevanssi_update_options` lets you adjust Relevanssi options immediately after the defaults are set. ``` -------------------------------- ### Relevanssi Sentence Query Variable Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt When the `sentence` query variable is used for phrase searching, Relevanssi now correctly adds quotes to the `highlight` parameter. ```php `sentence` query variable ``` -------------------------------- ### Enable WooCommerce Layered Navigation Compatibility Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt If WooCommerce layered navigation compatibility was causing issues, it can be re-enabled by adding this filter. This filter is used when compatibility was disabled by default. ```php add_filter( 'woocommerce_get_filtered_term_product_counts_query', 'relevanssi_filtered_term_product_counts_query' ); ``` -------------------------------- ### Enable fallback searches in Relevanssi Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The `relevanssi_fallback` filter provides a mechanism for performing fallback searches. This can be used to implement alternative search strategies when initial searches yield no results. ```php New filter: `relevanssi_fallback` allows you to do fallback searches. ``` -------------------------------- ### Filter Indexing Tokens with relevanssi_indexing_tokens Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt This filter allows you to modify the individual words (tokens) before they are indexed by Relevanssi. It's useful for custom text processing during indexing. ```php add_filter( 'relevanssi_indexing_tokens', 'my_custom_token_filter' ); function my_custom_token_filter( $tokens ) { // Modify $tokens array here return $tokens; } ``` -------------------------------- ### Remove Fusion Builder shortcodes from excerpts Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Fusion Builder shortcodes are now removed from excerpts. This prevents shortcode output from appearing in search result snippets. ```php Fusion builder shortcodes are removed from excerpts. ``` -------------------------------- ### Filter Relevanssi excerpt query Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The `relevanssi_excerpt_query` filter allows modification of the search query before excerpts are built. This provides flexibility in how excerpts are generated based on search parameters. ```php New filter: `relevanssi_excerpt_query` filters the search query before building excerpts. ``` -------------------------------- ### Define Sorting Order for Post Type Results with relevanssi_comparison_order Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Use this filter to control the sorting order when Relevanssi results are grouped or sorted by post type. This allows for custom ordering logic. ```php add_filter( 'relevanssi_comparison_order', 'my_custom_post_type_order' ); function my_custom_post_type_order( $order ) { // Modify $order array here return $order; } ``` -------------------------------- ### Managing Stopwords Source: https://context7.com/msaari/relevanssi/llms.txt Functions to programmatically manage the list of common words excluded from the search index. ```APIDOC ## PHP Functions: Stopword Management ### Description Provides methods to add, remove, fetch, and update the list of stopwords used by Relevanssi. ### Functions - **relevanssi_add_stopword(string $word, bool $verbose)** - Adds a word to the stopword list. - **relevanssi_remove_stopword(string $word, bool $verbose)** - Removes a word from the stopword list. - **relevanssi_fetch_stopwords()** - Returns an array of all current stopwords. - **relevanssi_remove_all_stopwords(bool $verbose)** - Clears all stopwords for the current language. - **relevanssi_update_stopwords(array $stopwords)** - Overwrites the current stopword list with the provided array. ``` -------------------------------- ### Remove error notices in Relevanssi code Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Several error notices in the Relevanssi code have been removed. This improves the stability and reduces unnecessary output in the logs. ```php Removed couple of error notices in the code. ``` -------------------------------- ### Improve single-word phrase handling Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Single-word phrases are no longer allowed as they are ineffective. They are now silently converted to non-phrases, improving search result quality. ```php Single-word phrases are not allowed anymore, as they do no good. They are silently converted to non-phrases now. ``` -------------------------------- ### Improve User Searches page Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The User Searches page has received a makeover. This likely includes UI enhancements and potentially new features for analyzing search queries. ```php The User Searches page got a makeover, too. ``` -------------------------------- ### Fix indexing bugs Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Various indexing bugs have been fixed. This ensures that the Relevanssi index is accurate and reliable. ```php Indexing bugs squashed. ``` -------------------------------- ### Block Bots from Logs with relevanssi_bots_to_not_log Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Use this filter to prevent specific bots from being logged. The format is compatible with other plugins like WP-Useronline for shared block lists. ```php add_filter( 'relevanssi_bots_to_not_log', 'my_relevanssi_block_bots' ); function my_relevanssi_block_bots( $bots ) { return array_merge( $bots, array( 'MyBot/1.0' ) ); } ``` -------------------------------- ### Fix MemberPress post control Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The post control for MemberPress was backwards. This has been corrected, ensuring proper control over post visibility with MemberPress. ```php MemberPress post control was backwards. ``` -------------------------------- ### ACF Field Exclusion Setting Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt ACF field settings now include an 'Exclude from Relevanssi index' option, allowing specific ACF fields to be omitted from the Relevanssi index. ```php 'Exclude from Relevanssi index' ``` -------------------------------- ### Control Admin Search Override with relevanssi_admin_search_ok Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt This filter allows more control over when Relevanssi overrides the default WordPress search in the admin area. It's useful for resolving issues with specific AJAX searches, like P2P_Box. ```php add_filter( 'relevanssi_admin_search_ok', 'my_relevanssi_admin_search_ok' ); function my_relevanssi_admin_search_ok( $ok ) { // Only allow override if not P2P_Box AJAX search if ( defined( 'P2P_BOX_AJAX' ) && P2P_BOX_AJAX ) { return false; } return $ok; } ``` -------------------------------- ### Update relevanssi_index_custom_fields filter Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The `relevanssi_index_custom_fields` filter now accepts a second parameter, the post ID, providing more context for filtering custom fields during indexing. ```php Updated filter: `relevanssi_index_custom_fields` now gets a second parameter that contains the post ID. ``` -------------------------------- ### Custom Search Form Filter with relevanssi_search_form Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt This filter works similarly to `get_search_form` but specifically targets search forms generated by the Relevanssi shortcode. Use it to customize the appearance or behavior of these forms. ```php add_filter( 'relevanssi_search_form', 'my_custom_search_form' ); function my_custom_search_form( $form ) { // Modify $form HTML here return $form; } ``` -------------------------------- ### Relevanssi Admin Search Paging Fix Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Paging in admin searches for hierarchical post types, such as pages, has been fixed to ensure proper navigation. ```php Paging didn't work in admin searches for hierarchical post types ``` -------------------------------- ### Add Category Dropdown to Search Form Shortcode Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Use the `dropdown` parameter in the `[searchform]` shortcode to include a category dropdown. This is useful for narrowing search scope by category. ```html [searchform dropdown="category"] ``` -------------------------------- ### Modify Excerpt Content with relevanssi_pre_excerpt_content Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt This filter allows modification of the content before it's used to generate excerpts. It was fixed in version 3.1 to work properly. ```php add_filter( 'relevanssi_pre_excerpt_content', 'my_relevanssi_modify_excerpt' ); function my_relevanssi_modify_excerpt( $content ) { // Example: Remove all shortcodes from excerpt content $content = strip_shortcodes( $content ); return $content; } ``` -------------------------------- ### Relevanssi Drafts and Pending Posts in Live Search Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Relevanssi now stops drafts and pending posts from appearing in Live Ajax Searches, improving the relevance of search results. ```php relevanssi Live Ajax Searches ``` -------------------------------- ### Control page builder shortcodes removed from excerpts Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The `relevanssi_page_builder_shortcodes` filter allows developers to specify which page builder shortcodes Relevanssi should remove before generating excerpts. This helps in creating cleaner excerpts. ```php New filter: `relevanssi_page_builder_shortcodes` lets you control which page builder shortcodes Relevanssi removes before building the excerpts. ``` -------------------------------- ### Fix post ordering code bug Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt A bug that was present in the post ordering code has been fixed. This resolves issues related to the order in which posts are displayed. ```php A bug was left in the post ordering code. That bug is now squashed. ``` -------------------------------- ### Prevent highlighting post titles when fetching only IDs Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt When using the `fields` parameter to fetch only post IDs, Relevanssi will no longer attempt to highlight post titles. This optimizes performance by avoiding unnecessary highlighting operations. ```php When using `fields` to only fetch post IDs, Relevanssi doesn't try to highlight post titles. ``` -------------------------------- ### Relevanssi Indexing Trigger Change Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The post update trigger for Relevanssi indexing has been changed to wp_after_insert_post for improved reliability and compatibility with other plugins. ```php wp_after_insert_post ``` -------------------------------- ### Fix User Searches page reset buttons Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The reset buttons on the User Searches page have been fixed. This ensures that the reset functionality works correctly. ```php User searches page reset buttons fixed. ``` -------------------------------- ### Relevanssi Fatal Error Prevention Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Prevents fatal errors that could occur from the `relevanssi_strip_all_tags()` function, ensuring more stable operation. ```php relevanssi_strip_all_tags() ``` -------------------------------- ### Relevanssi Excerpt Improvement Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Excerpts are now improved to prevent breaking HTML tags when tags are allowed, ensuring better display of content snippets. ```html avoid breaking HTML tags ``` -------------------------------- ### Enable Polylang language filter removal Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt A new option allows for the removal of the Polylang language filter. This provides better control over language-specific search results when using Polylang. ```php Better Polylang support. A new option to remove the Polylang language filter. ``` -------------------------------- ### Exclude Comments from Indexing with relevanssi_index_comments_exclude Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt This filter allows you to exclude specific comments from being indexed by Relevanssi. It receives the post ID as a parameter, enabling selective exclusion based on the post the comments belong to. ```php add_filter( 'relevanssi_index_comments_exclude', 'my_relevanssi_exclude_comments' ); function my_relevanssi_exclude_comments( $post_id ) { // Exclude comments for posts in category 'news' if ( has_term( 'news', 'category', $post_id ) ) { return true; } return false; } ``` -------------------------------- ### Fix WPML language filter Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt A fix has been implemented for the WPML language filter. This resolves issues related to language filtering in search results when using WPML. ```php WPML language filter fix. ``` -------------------------------- ### Display Relevance Score in WordPress Source: https://github.com/msaari/relevanssi/blob/master/readme.txt To display the relevance score used by Relevanssi for sorting results, add this line within a PHP code block in your search results template. Ensure Relevanssi is active and configured. ```php echo $post->relevance_score; ``` -------------------------------- ### Relevanssi Phrase Searching Fix Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt A fix prevents phrases from being treated as single words in cases where a multiple-word phrase might appear as a single word. ```php Phrases weren't used in some cases where a multiple-word phrase looked like a single-word phrase. ``` -------------------------------- ### Fix Gravity Forms shortcode in Relevanssi indexing Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Gravity Forms shortcodes are now disabled during Relevanssi indexing to prevent issues. This change ensures compatibility and prevents unexpected behavior when indexing content containing Gravity Forms. ```php Gravity Forms shortcode is now disabled in Relevanssi indexing. ``` -------------------------------- ### Modify punctuation handling in Relevanssi Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The `relevanssi_punctuation_filter` allows for easy modification of how punctuation is handled during indexing and searching. The `relevanssi_default_punctuation_replacement` filter changes the default replacement character for punctuation. ```php New filter: `relevanssi_punctuation_filter` allows for easy modification of punctuation handling. ``` ```php New filter: `relevanssi_default_punctuation_replacement` changes the default way to handle the rest of the punctuation. ``` -------------------------------- ### Update relevanssi_index_custom_fields filter with post ID Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The `relevanssi_index_custom_fields` filter has been updated to include the post ID as a second parameter. This provides more context when filtering custom fields during indexing. ```php New filter: `relevanssi_custom_field_value` is used to filter custom field values both before indexing and before excerpt-building. Parameters include the field name and the post ID. ``` ```php Updated filter: `relevanssi_index_custom_fields` now gets a second parameter that contains the post ID. ``` -------------------------------- ### Modify Indexed Custom Fields with relevanssi_index_custom_fields Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt This filter provides control over which custom fields are indexed by Relevanssi. You can use it to include or exclude specific custom fields based on your needs. ```php add_filter( 'relevanssi_index_custom_fields', 'my_relevanssi_index_custom_fields' ); function my_relevanssi_index_custom_fields( $fields ) { // Only index 'my_custom_field' return array( 'my_custom_field' ); } ``` -------------------------------- ### Filter custom field values for indexing and excerpts Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt The `relevanssi_custom_field_value` filter can be used to modify custom field values before they are indexed or used for building excerpts. It receives the field name and post ID as parameters. ```php New filter: `relevanssi_custom_field_value` is used to filter custom field values both before indexing and before excerpt-building. Parameters include the field name and the post ID. ``` ```php Fixed filter: `relevanssi_custom_field_value` didn't have the correct post ID parameter. ``` -------------------------------- ### Relevanssi Hyphenation of Search Terms Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Long search terms in the User searches page are now hyphenated to prevent display issues. This also helps prevent 'Did you mean' suggestions from including hyphens incorrectly. ```text hyphenates long search terms ``` -------------------------------- ### Fix post sorting bug with strings Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt A bug in post sorting that affected string sorting, primarily post title sorting, has been fixed. This ensures accurate sorting of string-based fields. ```php A bug in post sorting broke string sorting (mostly post title sorting). ``` -------------------------------- ### Filter Oxygen JSON Elements Source: https://github.com/msaari/relevanssi/blob/master/changelog.txt Use this filter hook to modify Oxygen JSON elements. This is the primary method for filtering Oxygen elements in version 4 and later, replacing older filter hooks. ```php relevanssi_oxygen_element ```