Skip to content

Instantly share code, notes, and snippets.

View msaari's full-sized avatar

Mikko Saari msaari

View GitHub Profile
@msaari
msaari / relevanssi-polylang-terms.php
Last active May 2, 2018 06:45
Allow taxonomy terms in Polylang language-limited search results
<?php
add_filter( 'relevanssi_where', 'rlv_polylang_tax_term' );
function rlv_polylang_tax_term( $where ) {
$current_language = pll_current_language();
$languages = get_terms( array( 'taxonomy' => 'language' ) );
$language_id = 0;
foreach ( $languages as $language ) {
if ( $language->slug === $current_language ) {
$language_id = $language->term_id;
@msaari
msaari / relevanssi_add_accent_variations.php
Last active April 27, 2018 12:30
relevanssi_add_accent_variations()
<?php
/**
* Adds accented variations to letters.
*
* In order to have non-accented letters in search terms match the accented terms in
* full text, this function adds accent variations to the search terms.
*
* @param string $word The word to manipulate.
*
@msaari
msaari / wordgamesolver.php
Last active April 12, 2018 03:42
Word game solver
<?php
$begin_time = microtime( true );
$material = <<<EOF
N1 E1 F3 W3 J4
S1 E1 O1 I1 H3
B2 V3 Y3 T1 N1
G2 R1 O1 T1 D2
U1 A1 D2 L1 M2
@msaari
msaari / hakusysteemit.php
Created December 11, 2017 13:59
Relevanssin hakusysteemit
<?php
// Lisää nämä teeman functions.php-tiedostoon.
add_filter('relevanssi_modify_wp_query', 'rlv_liitteet');
function rlv_liitteet($query) {
if (!isset($query->query_vars['post_types'])) {
$query->set("post_types", array("post,page,news"));
}
@msaari
msaari / relevanssi-create-tables.sql
Created December 6, 2017 04:19
Relevanssi create tables
CREATE TABLE `wp_relevanssi` (
`doc` bigint(20) NOT NULL DEFAULT '0',
`term` varchar(50) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '0',
`term_reverse` varchar(50) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '0',
`content` mediumint(9) NOT NULL DEFAULT '0',
`title` mediumint(9) NOT NULL DEFAULT '0',
`comment` mediumint(9) NOT NULL DEFAULT '0',
`tag` mediumint(9) NOT NULL DEFAULT '0',
`link` mediumint(9) NOT NULL DEFAULT '0',
`author` mediumint(9) NOT NULL DEFAULT '0',
@msaari
msaari / relevanssi-remove-trademarks.php
Created December 5, 2017 18:10
Relevanssi remove trademarks
<?php
/* Add this to theme functions.php and rebuild the index. */
add_filter('relevanssi_remove_punctuation', 'rlv_remove_trademark', 9);
function rlv_remove_trademark($a) {
$a = str_replace('®', '', $a);
return $a;
}
?>
@msaari
msaari / relevanssi-custom-field-filter.php
Last active December 6, 2017 04:48
Relevanssi custom field filter
<?php
// Add all three functions to theme functions.php, then call rlv_customfield_dropdown() on your search results template
add_filter('relevanssi_hits_filter', 'rlv_gather_categories', 99);
function rlv_gather_categories($hits) {
global $rlv_categories_present;
$rlv_categories_present = array();
$posts = array();
$today = date("Y-m-d");
@msaari
msaari / looser-fuzzy-query.php
Created November 24, 2017 15:09
Looser fuzzy query
<?php
add_filter('relevanssi_fuzzy_query', 'rlv_loose_fuzzy');
function rlv_loose_fuzzy($fuzzy) {
return "(term LIKE '%#term#%')";
}
?>
@msaari
msaari / relevanssi-simple-membership.php
Last active November 18, 2017 04:00
Relevanssi Simple Membership support
<?php
// Version 1
// Add this to theme functions.php.
add_filter('relevanssi_post_ok', 'rlv_simple_membership', 10, 2);
function rlv_simple_membership($post_ok, $post_id) {
$access_ctrl = SwpmAccessControl::get_instance();
$post_ok = $access_ctrl->can_i_read_post($post_id);
return $post_ok;
@msaari
msaari / relevanssi-only-one-parent.php
Created November 15, 2017 10:39
Index only children of one parent page
<?php
// Add this to theme functions.php and replace XXX with the parent page ID.
add_filter('relevanssi_do_not_index', 'rlv_page_control', 10, 2);
function rlv_page_control($block, $post_id) {
$parent = get_post_parent_id($post_id);
if ($parent != XXX) $block = true;
return $block;
}