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 | |
// **********************************************************************// | |
// Enfold Search WP integration */ | |
// **********************************************************************// | |
add_filter( 'avf_ajax_search_function', 'avia_init_searchwp', 10, 4 ); | |
function avia_init_searchwp( $function_name, $search_query, $search_parameters, $defaults ) { | |
$function_name = class_exists( 'SWP_Query' ) ? 'avia_searchwp_search' : $function_name; | |
return $function_name; |
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 | |
// 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; |
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 | |
// Integrate SearchWP with JetSmartFilters search using | |
// JetEngine Listing Grid to display results. | |
add_action( 'pre_get_posts', function( $wp_query ) { | |
if ( | |
! isset( $wp_query->query['jet_smart_filters' ] ) | |
|| empty( $wp_query->query['s'] ) | |
) { | |
return; |
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 secondary sort to SearchWP results to sort matching | |
// relevance results by Title in ASC order. | |
add_filter( 'searchwp\query\mods', function( $mods, $query ) { | |
global $wpdb; | |
$mod = new \SearchWP\Mod(); | |
$mod->set_local_table( $wpdb->posts ); |
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 Native/Default results to Category that has 'foobar' slug. | |
add_filter( 'searchwp\native\args', function( $args, $query ) { | |
if ( ! isset( $args['tax_query'] ) || ! is_array( $args['tax_query'] ) ) { | |
$args['tax_query'] = []; | |
} | |
$args['tax_query'][] = [ | |
'taxonomy' => 'category', |
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 Category that has 'foobar' slug. | |
$search = new \SWP_Query( [ | |
's' => 'coffee', // Search string. | |
'tax_query' => [ [ | |
'taxonomy' => 'category', | |
'field' => 'slug', | |
'terms' => 'foobar', | |
] ], |
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 a SearchWP custom Custom Field to append Gmedia Media Tags to Gmedia Albums when | |
// indexing, making Gmedia Tags searchable, with Albums coming up for search results. | |
// @link https://wordpress.org/plugins/grand-media/ | |
add_filter( 'searchwp\entry\data', function( $data, \SearchWP\Entry $entry ) { | |
global $gmDB, $wpdb; | |
if ( 'post' . SEARCHWP_SEPARATOR . 'gmedia_album' !== $entry->get_source()->get_name() ) { | |
return $data; |
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 | |
// Control SearchWP AND logic token threshold. | |
// @link https://searchwp.com/documentation/hooks/searchwp-query-logic-and-token_threshold/ | |
add_filter( 'searchwp\query\logic\and\token_threshold', function( $threshold, $args ) { | |
// If the search contains 'coffee' allow up to 10 tokens for AND logic. | |
if ( in_array( 'coffee', $args['tokens'], true ) ) { | |
$threshold = 10; | |
} | |
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 | |
// Disable SearchWP AND logic token threshold, allowing AND logic for all searches. | |
// @link https://searchwp.com/documentation/hooks/searchwp-query-logic-and-token_threshold/ | |
add_filter( 'searchwp\query\logic\and\token_threshold', '__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 | |
// Customize SearchWP Engine used. | |
add_filter( 'searchwp\native\args', function( $args, $query ) { | |
$args['engine'] = 'supplemental'; | |
return $args; | |
}, 15, 2 ); |