Skip to content

Instantly share code, notes, and snippets.

Avatar

Mikko Saari msaari

View GitHub Profile
@msaari
msaari / base64_decode.php
Created Apr 9, 2021
Base64 decoding code block content
View base64_decode.php
<?php
add_filter( 'relevanssi_oxygen_section_content', function( $content ) {
if ( preg_match_all( '/\[ct_code_block.*?ct_code_block\]/', $content, $matches ) ) {
foreach ( $matches[0] as $match ) {
if ( preg_match_all( '/"code-php":"(.*?)"/', $match, $block_matches ) ) {
foreach ( $block_matches[1] as $encoded_text ) {
$content .= base64_decode( $encoded_text );
}
}
@msaari
msaari / relevanssilight.sql
Created Apr 9, 2021
Relevanssi Light database alterations
View relevanssilight.sql
ALTER TABLE xx_posts ADD COLUMN `relevanssi_light_data` LONGTEXT
ALTER TABLE xx_posts ADD FULLTEXT `relevanssi_light_fulltext` (`post_title`,`post_content`,`post_excerpt`,`relevanssi_light_data`)
@msaari
msaari / functions.php
Created Dec 29, 2020
Excluding posts from the Relevanssi index
View functions.php
<?php
// Put this in your theme functions.php
add_filter( 'relevanssi_do_not_index', 'rlv_skip_page', 10, 2 );
function rlv_skip_page( $skip, $page ) {
$excluded_pages = array( 123, 234 ); // List all the ID numbers of the excluded pages here.
if ( in_array( $page, $excluded_pages, true ) ) {
$skip = true;
}
return $skip;
@msaari
msaari / oxygen.php
Created Nov 14, 2020
Improved Oxygen compatibility
View oxygen.php
<?php
/**
* /lib/compatibility/oxygen.php
*
* Oxygen Builder compatibility features.
*
* @package Relevanssi
* @author Mikko Saari
* @license https://wordpress.org/about/gpl/ GNU General Public License
* @see https://www.relevanssi.com/
@msaari
msaari / paidmembershippro.php
Created Oct 27, 2020
/lib/compatibility/paidmembershippro.php
View paidmembershippro.php
<?php
/**
* /lib/compatibility/paidmembershippro.php
*
* Paid Membership Pro compatibility features.
*
* @package Relevanssi
* @author Mikko Saari
* @license https://wordpress.org/about/gpl/ GNU General Public License
* @see https://www.relevanssi.com/
@msaari
msaari / functions.php
Created Oct 15, 2020
Block Formidable Forms entries
View functions.php
<?php
// Add this to theme functions.php and rebuild the index to remove Formidable Forms entries from index
add_filter( 'relevanssi_indexing_restriction', 'rlv_no_formidable' );
function rlv_no_formidable( $restriction ) {
global $wpdb;
$restriction['mysql'] .= " AND post.ID NOT IN (SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value LIKE 'formidable%' ) ";
$restriction['reason'] .= ' No Formidable Forms entries';
return $restriction;
}
@msaari
msaari / indexing.php
Created Aug 28, 2020
Relevanssi indexing.php without doc count update
View indexing.php
<?php
/**
* /lib/indexing.php
*
* @package Relevanssi
* @author Mikko Saari
* @license https://wordpress.org/about/gpl/ GNU General Public License
* @see https://www.relevanssi.com/
*/
@msaari
msaari / rlv_category_dropdown.php
Last active Jul 20, 2020
Improved rlv_category_dropdown
View rlv_category_dropdown.php
<?php
function rlv_category_dropdown() {
global $rlv_categories_present, $wp_query;
$select = "<div id='catCheckboxes'><p>Choose a category:</p>";
$cat_params = array_map( 'intval', explode( ',', $wp_query->query_vars['cats'] ) );
foreach ( $rlv_categories_present as $cat_id => $cat_name ) {
$checked = '';
if ( in_array( $cat_id, $cat_params, true ) ) {
@msaari
msaari / relevanssi_index_tablepress_acf.php
Last active Jun 27, 2020
Index TablePress shortcodes in ACF fields
View relevanssi_index_tablepress_acf.php
<?php
add_filter( 'relevanssi_custom_field_value', 'rlv_tablepress_in_acf' );
function rlv_tablepress_in_acf( $value ) {
$tablepress_controller = relevanssi_enable_tablepress_shortcodes();
$post_before_shortcode = $post;
$value[0] = do_shortcode( $value[0] );
$post = $post_before_shortcode;
View gist:3d59794052e97fa6f09194f4364f514e
<?php
add_action('template_redirect', 'one_match_redirect');
function one_match_redirect() {
if (is_search()) {
global $wp_query;
if ($wp_query->post_count == 1) {
wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
exit();
}