This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Limit SearchWP results to chosen Category from dropdown. | |
// @link https://searchwp.com/documentation/knowledge-base/category-select-dropdown/ | |
add_filter( 'searchwp\query\mods', function( $mods, $query ) { | |
global $wpdb; | |
// Only proceed if a Category was chosen from the dropdown. | |
if ( ! isset( $_GET['swp_category_limiter'] ) || empty( intval( $_GET['swp_category_limiter'] ) ) ) { | |
return $mods; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Give Pages extraordinary weight boost to ensure Pages show up first. | |
add_filter( 'searchwp\query\mods', function( $mods ) { | |
$post_type = 'page'; | |
$source = \SearchWP\Utils::get_post_type_source_name( $post_type ); | |
$mod = new \SearchWP\Mod( $source ); | |
$mod->weight( function( $runtime ) use ( $source ) { | |
return "IF( {$runtime->get_foreign_alias()}.source = '{$source}', '999999999999', '0' )"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Execute a search using our supplemental SearchWP Engine. | |
$search_query = isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : null; | |
$search_results = []; | |
if ( ! empty( $search_query ) && class_exists( '\\SearchWP\\Query' ) ) { | |
$searchwp_query = new \SearchWP\Query( $search_query, [ | |
'engine' => 'supplemental', // The Engine name. | |
'fields' => 'all', // Load proper native objects of each result. | |
] ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* SearchWP Modal Form Name: Term Archive | |
*/ | |
?> | |
<div class="searchwp-modal-form-default"> | |
<div class="searchwp-modal-form__overlay" tabindex="-1" data-searchwp-modal-form-close> | |
<div class="searchwp-modal-form__container" role="dialog" aria-modal="true"> | |
<main class="searchwp-modal-form__content"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Implement a max length for global excerpt generation in SearchWP. | |
add_filter( 'searchwp\source\post\excerpt_haystack', function( $haystack ) { | |
$max_length = 10000; | |
if ( strlen( $haystack ) > $max_length ) { | |
$haystack = substr( $haystack, 0, $max_length ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Conditionally remove a SearchWP Engine Source. | |
add_filter( 'searchwp\query\before', function( $query ) { | |
// Applies only if `myflag` GET variable exists. | |
if ( ! isset( $_GET['myflag'] ) ) { | |
return; | |
} | |
// Remove Posts from Engine. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Sort SearchWP results in alphabetical 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', 1 ); | |
$mods[] = $mod; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Customize SearchWP stopwords per Engine. | |
*/ | |
// Optional: remove all Stopwords so you can add only unique Stopwords per Engine. | |
add_filter( 'searchwp\stopwords', '__return_empty_array' ); | |
// Add unique stopword(s) for a single SearchWP Engine. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add unique stopword(s) for a single SearchWP Engine. | |
add_filter( 'searchwp\query\search_string', function( $search_string, $query ) { | |
// Remove "apple" and "orange" for my_engine searches. | |
if ( 'my_engine' === $query->get_engine() ) { | |
$search_string = str_replace( [ 'apple', 'orange' ], '', $search_string ); | |
} | |
return $search_string; |