Skip to content

Instantly share code, notes, and snippets.

@BrElio
BrElio / searchwp_removearabic.php
Last active February 23, 2023 11:50 — forked from gerald-drissner/searchwp_removearabic.php
Removes all kind of Arabic diacritical signs and markers and replaces them with their plain letter form. For the use of SearchWP Wordpress plugin.
<?php
/*
Plugin Name: SearchWP Remove Arabic Diacritics
Description: Removes all kind of إعراب-signs as well as تشكيل-signs for the use of SearchWP Wordpress plugin.
Author: Gerald Drissner
Note: This is a fork and extension of https://gist.github.com/BrElio/bd84d8035278adf834b29ec5e1187567 and Relevannsi's code snippet regarding foreign languages.
Version: 1.0.0
Last update: 2022-10-20
*/
@BrElio
BrElio / searchwp-customizations.php
Created August 23, 2022 11:08 — forked from jchristopher/searchwp-customizations.php
Enable full wpDataTables table Shortcode parsing when SearchWP indexer is running
<?php
// wpDataTables compatibility with SearchWP. Retrieve entire data table
// if the indexer is running (regardless of wpDataTables settings) to ensure
// all wpDataTables Shortcode content is indexed when parsing Shortcodes.
add_filter( 'wpdatatables_filter_table_metadata', function( $data, $table_id ) {
if ( did_action( 'searchwp\indexer\batch' ) ) {
$data->pagination = false;
$data->showAllRows = true;
$data->server_side = false;
@BrElio
BrElio / searchwp-customizations.php
Created April 19, 2022 14:52 — forked from jchristopher/searchwp-customizations.php
Sort SearchWP WP_Post Results alphabetically by Title in ascending order
<?php
// Sort SearchWP WP_Post Results alphabetically by Title in ascending order.
add_filter( 'searchwp\query\mods', function( $mods ) {
$mod = new \SearchWP\Mod( \SearchWP\Utils::get_post_type_source_name( 'post' ) );
$mod->order_by( function( $mod ) {
return $mod->get_local_table_alias() . '.post_title';
}, 'ASC', 9 );
$mods[] = $mod;
@BrElio
BrElio / search-results.php
Created February 25, 2022 14:46 — forked from jchristopher/search-results.php
Output SearchWP Live Ajax Search results grouped by Category taxonomy term
<?php
/**
* Search results are contained within a div.searchwp-live-search-results
* which you can style accordingly as you would any other element on your site
*
* Some base styles are output in wp_footer that do nothing but position the
* results container and apply a default transition, you can disable that by
* adding the following to your theme's functions.php:
*
* add_filter( 'searchwp_live_search_base_styles', '__return_false' );
@BrElio
BrElio / searchwp-customizations.php
Created October 15, 2021 10:54 — forked from jchristopher/searchwp-customizations.php
Randomize SearchWP results
<?php
// Randomize SearchWP search results.
add_filter( 'searchwp\query\mods', function( $mods ) {
$mod = new \SearchWP\Mod();
$mod->order_by( 'random', null, 1 );
$mods[] = $mod;
return $mods;
} );
@BrElio
BrElio / searchwp-customizations.php
Last active August 11, 2021 10:05 — forked from jchristopher/searchwp-customizations.php
Limit SearchWP results to Posts and Pages.
<?php
// Limit SearchWP results to Posts and Pages.
add_filter( 'searchwp\query\mods', function( $mods, $query ) {
$mod = new \SearchWP\Mod();
$mod->set_where( [ [
'column' => 'source',
'value' => [
\SearchWP\Utils::get_post_type_source_name( 'post' ),
<?php
// tell SearchWP to process shortcodes
add_filter( 'searchwp_do_shortcode', '__return_true' );
// if the SearchWP indexer is running prevent returning the
// content between [searchwp_no_index] and [/searchwp_no_index]
function shortcode_searchwp_no_index( $atts, $content = null ) {
// if the searchwp_indexer_running action fired, the indexer is running so don't return anything
return did_action( 'searchwp_indexer_running' ) ? '' : $content;
@BrElio
BrElio / searchwp-customizations.php
Created July 20, 2021 13:47 — forked from jchristopher/searchwp-customizations.php
Automatically link to WooCommerce Product Variation permalink in SearchWP.
<?php
// @link https://searchwp.com/documentation/knowledge-base/add-woocommerce-product-variations-to-products/
// When using SearchWP it's necessary to disable WooCommerce's insistance on
// automatically redirecting to a single search result without showing the
// search results page, when that happens this hook doesn't run!
// Willing to bet this can be edited to accommodate, tips are welcome!
add_filter( 'woocommerce_redirect_single_search_result', '__return_false' );
@BrElio
BrElio / searchwp-customizations.php
Last active December 10, 2020 11:15 — forked from jchristopher/searchwp-customizations.php
Add extra weight to specific post types
<?php
//Add extra weight to specific post types
add_filter( 'searchwp\query\mods', function( $mods ) {
$source_extra_weight = [
\SearchWP\Utils::get_post_type_source_name( 'post') => 100000,
\SearchWP\Utils::get_post_type_source_name( 'page') => 1000,
];
@BrElio
BrElio / functions.php
Last active October 24, 2019 12:51 — forked from jchristopher/functions.php
Override SearchWP's "Did you mean?" output
<?php
// Override SearchWP's "Did you mean?" output.
class MySearchwpDidYouMean {
private $args;
function __construct() {
// Prevent SearchWP's automatic "Did you mean?" output.
add_filter( 'searchwp_auto_output_revised_search_query', '__return_false' );
// Grab the "Did you mean?" arguments to use later.