Skip to content

Instantly share code, notes, and snippets.

@jchristopher
jchristopher / gist:7861980
Last active December 30, 2015 17:38
Limit all SearchWP searches to 5 words instead of the default 6
<?php
function my_searchwp_max_search_terms( $maxTerms, $engine ) {
// limit to 5 search terms
return 5;
}
add_filter( 'searchwp_max_search_terms', 'my_searchwp_max_search_terms', 10, 2 );
@jchristopher
jchristopher / gist:7862007
Created December 8, 2013 18:43
Limit supplemental search engine search queries to 7 terms, but not the default search engine search queries
<?php
function my_searchwp_max_search_terms_supplemental( $maxTerms, $engine ) {
// limit to 7 search terms for all supplemental search engines, not the default
return 7;
}
add_filter( 'searchwp_max_search_terms_supplemental', 'my_searchwp_max_search_terms_supplemental', 10, 2 );
@jchristopher
jchristopher / gist:7862022
Created December 8, 2013 18:44
Use a supplemental search engine name to reset the limit on number of accepted search terms per search query
<?php
function my_searchwp_max_search_terms_my_search_engine( $maxTerms ) {
// limit to 8 search terms for My Supplemental Search Engine ONLY
return 8;
}
add_filter( 'searchwp_max_search_terms_my_search_engine', 'my_searchwp_max_search_terms_my_search_engine', 10, 2 );
@jchristopher
jchristopher / gist:7862124
Created December 8, 2013 18:53
Change the number of posts SearchWP indexes with each pass of the indexer
<?php
function my_searchwp_index_chunk_size() {
// index 15 posts at a time instead of the default 10
return 15;
}
add_filter( 'searchwp_index_chunk_size', 'my_searchwp_index_chunk_size' );
@jchristopher
jchristopher / gist:7862285
Created December 8, 2013 19:04
Turn on SearchWP debugging (writes to debug.log in ~/plugins/searchwp)
<?php
// enable SearchWP debugging
add_filter( 'searchwp_debug', '__return_true' );
@jchristopher
jchristopher / gist:7862399
Created December 8, 2013 19:08
Alter the SearchWP search engine settings after a search was submitted but not yet queried
<?php
function my_searchwp_engine_settings_default( $settings, $query ) {
// print_r( $query ); // uncomment this line to see the query structure
// if the visitor searched for soccer, boost the title weight a bit
if( in_array( 'soccer', $query ) ) {
// print_r( $settings ); // uncomment this line to see the settings structure
if( isset( $settings['post']['weights']['title'] ) ) {
$settings['post']['weights']['title'] = 15;
}
@jchristopher
jchristopher / gist:7862503
Last active May 6, 2019 20:33
Modify the SearchWP search terms after all sanitization has taken place
<?php
function my_searchwp_pre_search_terms( $terms, $engine ) {
if ( 'myengine' == $engine ) {
// do something with the terms
}
return $terms;
}
@jchristopher
jchristopher / gist:7862575
Created December 8, 2013 19:22
Control whether SearchWP searches return an array of WordPress Post objects, or simply an array of their IDs
<?php
function my_maybe_searchwp_load_posts( $loadPosts, $args ) {
// print_r( $args ); // uncomment this line to see the engine arguments
return false; // return only post IDs
}
add_filter( 'searchwp_load_posts', 'my_maybe_searchwp_load_posts', 10, 2 );
@jchristopher
jchristopher / gist:7862695
Created December 8, 2013 19:26
Tell SearchWP to completely ignore Media both when indexing and searching
<?php
add_filter( 'searchwp_index_attachments', '__return_false' );
@jchristopher
jchristopher / gist:7862735
Created December 8, 2013 19:29
Directly manipulate the actual SQL executed in the main search algorithm of SearchWP
<?php
function my_searchwp_query_conditions( $sql, $postType, $engine ) {
// modify $sql to your liking
return $sql;
}
add_filter( 'searchwp_query_conditions', 'my_searchwp_query_conditions', 10, 3 );