Skip to main contentSkip to footer

The main customisation for Relevanssi Light is to add more content to the index. For custom fields, it’s easiest to use the relevanssi_light_custom_fields filter hook. Give the hook an array of custom field names, and the plugin will include the contents of those custom fields in the full-text index.

If you want to add more content, you may need to override the relevanssi_light_update_post_data() function. It’s pluggable so that you can override it from a must-use plugin. Here’s an example plugin that will include the post author’s name in the full-text index:

<?php
/**
 * Plugin Name: Relevanssi Light Override
 * Plugin URI: https://www.domain.com
 * Description: Overrides Relevanssi Light post data update.
 * Version: 1
 * Author: Mikko Saari
 * Author URI: https://www.relevanssi.com/
 * License: GPLv2 or later
 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
 */

if ( ! function_exists( 'relevanssi_light_update_post_data' ) ) {
  function relevanssi_light_update_post_data( $post_id ) {
    global $wpdb;

    // Fetch the author ID and use that to get the author name.
    $author_id = (int) $wpdb->get_var(
      $wpdb->prepare( "SELECT post_author FROM {$wpdb->posts} WHERE ID = %d ", $post_id )
    );
    $author_name = get_the_author_meta( 'display_name', $author_id );

    // Update the post to add the author name to the relevanssi_light_data column.
    $wpdb->update(
      $wpdb->posts,
      array( 'relevanssi_light_data' => $author_content ),
      array( 'ID' => $post_id ),
      array( '%s' ),
      array( '%d' )
    );
  }
}

Save this as a file in the /wp-content/mu-plugins/ folder.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Indexing and searching PDFs in WordPress

…the Media library, and they become posts with the post type of attachment. Relevanssi can only parse and read PDF files that contain text. If the PDF file is all images, Relevanssi cannot read it. An easy way to check is to try to select the text in a PDF……reader. If you can select the text, Relevanssi can read it, but if you can’t, the text is an image (for example, a scanned document that hasn’t been OCR processed), and Relevanssi can’t read it. The indexing server has a hard file size limit of 256 megabytes. What about other……to read the file contents. If everything goes well, the page will reload, and an “Attachment Content” text box will appear, showing you the file content as seen by the Relevanssi extractor. If there’s a problem, an “Attachment Error” box will appear with the error message. Relevanssi attachment controls for…

WooCommerce: Hidden products in search

Relevanssi by default shows out-of-stock and excluded from catalogue WooCommerce products in the search results, but hides those set to excluded from search (before 2.2.2 and 4.1.2 the default behaviour was to show all products). It is quite easy to make Relevanssi not display hidden products in the results. The…products from the search. This method leads to much faster indexing times. Add this to your site: add_filter( ‘relevanssi_woocommerce_indexing’, ‘rlv_woocommerce_filter’ ); function rlv_woocommerce_filter( $blocks ) { $blocks[‘outofstock’] = true; $blocks[‘exclude-from-catalog’] = true; $blocks[‘exclude-from-search’] = true; return $blocks; } There’s one key for each product visibility level, set the ones you……), ‘product_visibility’, $post_id ) ) { $block = true; } return $block; } This code will unindex products that are set to be excluded from the catalogue, excluded from search or that are out of stock. If you want to keep out of stock items in the search results, just…

Yoast Local SEO
Yoast Local SEO plugin breaks Relevanssi search. It enhances the search by adding meta queries. Unfortunately they don’t work with…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed