Skip to content

Instantly share code, notes, and snippets.

View msaari's full-sized avatar

Mikko Saari msaari

View GitHub Profile
@msaari
msaari / suomi_stemmer.php
Last active January 29, 2019 12:54
Suomenkielinen Porter stemmer
<?php
add_filter( 'relevanssi_stemmer', 'suomi_stemmer' );
function suomi_stemmer( $merkkijono ) {
$stemmer = new FinnishStemmer();
return $stemmer->process( $merkkijono );
}
class FinnishStemmer {
@msaari
msaari / wpml-filter.php
Last active January 21, 2019 13:09
Creative WPML filter
<?php
remove_filter( 'relevanssi_hits_filter', 'relevanssi_wpml_filter' );
add_filter( 'relevanssi_hits_filter', 'creative_wpml_filter' );
function creative_wpml_filter( $data ) {
$filtered_hits = array();
foreach ( $data[0] as $hit ) {
if ( is_integer( $hit ) ) {
// In case "fields" is set to "ids", fetch the post object we need.
@msaari
msaari / rlv_array_reducer.php
Last active February 1, 2019 04:42
Relevanssi Langwitch support
<?php
// Add these to theme functions.php and go save the pages.
add_filter( 'relevanssi_content_to_index', 'rlv_langwitch_elements', 10, 2 );
function rlv_langwitch_elements( $content, $post ) {
$elements = get_option( '_alt_langwitch_elements_opts_page_' . $post->ID );
$element_content = '';
foreach ( $elements as $item ) {
$value = rlv_process_array( $item );
@msaari
msaari / rlv_title_stopwords.php
Created November 10, 2018 03:57
Indexing some stopwords for titles
<?php
// Instructions:
// 1. Remove the stopwords you want to enable in titles from the stopword list.
// 2. List them in the function below.
// 3. Add these functions to the theme functions.php.
// 4. Rebuild the index.
add_filter( 'relevanssi_index_titles', 'rlv_remove_stopwords' );
function rlv_remove_stopwords( $index_titles ) {
@msaari
msaari / rlv-slashes.php
Created November 7, 2018 17:39
Remove slashes when indexing
<?php
// Add this to theme functions.php and rebuild the index:
add_filter('relevanssi_punctuation_filter', 'rlv_handle_slashes' );
function rlv_handle_slashes( $replacements ) {
$replacements['/'] = '';
return $replacements;
}
@msaari
msaari / rlv_category_sort.php
Last active October 26, 2018 03:05
Relevanssi category sorting
<?php
// Add this to theme functions.php
add_filter( 'relevanssi_hits_filter', 'rlv_category_sort' );
function rlv_category_sort( $hits ) {
$gold = array();
$silver = array();
$bronze = array();
$everything_else = array();
@msaari
msaari / rlv_woo_stocklevel_boost.php
Created October 25, 2018 03:40
WooCommerce weight boost for products in stock.
<?php
// Add this to theme functions.php.
add_filter( 'relevanssi_match', 'rlv_woo_stocklevel' );
function rlv_woo_stocklevel( $match ) {
$in_stock = true;
if ( has_term( 'outofstock', 'product_visibility', $match->doc ) ) {
// Product is not in stock.
$in_stock = false;
@msaari
msaari / relevanssi-index-slug.php
Created October 22, 2018 05:36
Index slugs for Relevanssi
<?php
/**
* Adds the post slug to the post content, with dashes replaced with spaces.
* Add this to theme functions.php and rebuild the index.
*
* @param string $content The additional post content.
* @param object $post The post object.
*/
add_filter( 'relevanssi_content_to_index', 'rlv_index_slug', 10, 2 );
function rlv_index_slug( $content, $post ) {
@msaari
msaari / relevanssi-index-slug.php
Created October 22, 2018 04:35
Index post slugs for Relevanssi
<?php
/**
* Adds the post slug to the post content, with dashes replaced with spaces.
* Add this to theme functions.php and rebuild the index.
*
* @param string $content The additional post content.
* @param object $post The post object.
*/
add_filter( 'relevanssi_content_to_index', 'rlv_index_slug', 10, 2 );
@msaari
msaari / relevanssi-user-search.php
Created October 10, 2018 06:44
Relevanssi user profile search with custom field weighting
<?php
// First, make sure user profiles are indexed with the meta fields.
// Here's how you run the search. Get the search terms from wherever and place them in $search_terms.
$args = array(
's' => $search_terms,
'post_types' => 'user',
'posts_per_page' => 10,