Skip to content

Instantly share code, notes, and snippets.

@BrElio
BrElio / gist:df0fafc71c41a31f031b76ad77f3d466
Created December 4, 2017 17:24 — forked from jchristopher/gist:3135783eb3521bebbc5e
Disable the default SearchWP Live Search results theme CSS while retaining the positioning
<?php
function my_remove_searchwp_live_search_theme_css() {
wp_dequeue_style( 'searchwp-live-search' );
}
add_action( 'wp_enqueue_scripts', 'my_remove_searchwp_live_search_theme_css', 99 );
@BrElio
BrElio / gist:e8b2bdb18b480c6c44836c9174038929
Created February 5, 2018 09:19 — forked from jchristopher/gist:596cab51f1ec6727cb4a
Include Download Monitor post type in SearchWP
<?php
function my_dlm_cpt_dlm_download_args( $args ) {
$args['exclude_from_search'] = false;
return $args;
}
add_filter( 'dlm_cpt_dlm_download_args', 'my_dlm_cpt_dlm_download_args' );
@BrElio
BrElio / wp-tweaks.php
Last active October 22, 2019 13:19 — forked from jenniferhail/wp-tweaks.php
Index layouts relationship fields for SearchWP
// Adds additional processing for ACF field with the name my_acf_relationship_field
function my_searchwp_acf_relationship_processor( $customFieldValue, $customFieldName, $thePost ){
$content_to_index = '';
if ( 'partner_filter' == $customFieldName ) {
$partner_filter = $customFieldValue[0];
}
preg_match( '/^layouts_\d+_post_type/i', $customFieldName, $matches );
if( 'post_type' == $customFieldName || ( ! empty( $matches ) && is_array( $customFieldValue ) && ! empty( $customFieldValue ) ) ){
$post_type = $customFieldValue[0];
@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.
@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 / 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' );
<?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
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' ),
@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 / 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' );