Skip to content

Instantly share code, notes, and snippets.

<?php
function afterUserUpdate( $meta_id, $object_id, $meta_key, $_meta_value ) {
$userID = $object_id;
// $userID was updated
}
add_action( 'updated_user_meta', 'afterUserUpdate', 10, 4 );
@jchristopher
jchristopher / gist:7852221
Created December 8, 2013 01:20
SearchWP's default common words
<?php
$common = array(
"a", "about", "after", "ago", "all", "am", "an", "and", "any", "are", "aren't", "as", "at", "be", "but", "by",
"for", "from", "get", "go", "how", "if", "in", "into", "is", "isn't", "it", "its", "me", "more", "most", "must",
"my", "new", "news", "no", "none", "not", "nothing", "of", "off", "often", "old", "on", "once", "only", "or",
"other", "our", "ours", "out", "over", "page", "she", "should", "small", "so", "some", "than", "true", "thank",
"that", "the", "their", "theirs", "them", "then", "there", "these", "they", "this", "those", "thus", "time",
"times", "to", "too", "under", "until", "up", "upon", "use", "users", "version", "very", "via", "want", "was",
"way", "web", "were", "what", "when", "where", "which", "who", "whom", "whose", "why", "wide", "will", "with",
@jchristopher
jchristopher / gist:7852314
Last active April 26, 2019 14:34
Replace the default SearchWP stopwords with your own
<?php
function my_searchwp_stopwords( $terms ) {
// replace the default SearchWP default common words with 'lorem', 'ipsum', and 'dolor' ONLY
$terms = array( 'lorem', 'ipsum', 'dolor' );
return $terms;
}
add_filter( 'searchwp_stopwords', 'my_searchwp_stopwords' );
@jchristopher
jchristopher / gist:7852448
Created December 8, 2013 01:58
Control whether SearchWP applies it's own term sanitization
<?php
function my_searchwp_sanitize_terms( $enabled, $engine )
{
if( $engine == 'default' ) {
// if it's the default engine, use SearchWP's sanitizing
return true;
} else {
// for supplemental engines disable automatic sanitization
return false;
@jchristopher
jchristopher / gist:7852506
Created December 8, 2013 02:12
Customize the query submitted to SearchWP before the search actually takes place
<?php
// if your visitors commonly misspell "soccer" as "socer" you can fix that for them
function my_parse_searchwp_terms( $query, $engine ) {
if( false !== strpos( strtolower( $query ), 'socer' ) ) {
$query = str_replace( 'socer', 'soccer', strtolower( $query ) );
}
return $query;
}
@jchristopher
jchristopher / gist:7852546
Last active February 12, 2020 13:42
Customize the number of posts per page in SearchWP results
<?php
function my_searchwp_posts_per_page( $posts_per_page, $engine, $terms, $page )
{
if( $engine != 'default' ) {
// if this is a supplemental search engine, show 20 results per page
return 20;
} else {
// it's the default search engine, return whatever it was originally
return $posts_per_page;
@jchristopher
jchristopher / gist:7852613
Created December 8, 2013 02:28
Enable SearchWP's algorithm when performing searches in the WordPress admin
<?php
add_filter( 'searchwp_in_admin', '__return_true' );
@jchristopher
jchristopher / gist:7852683
Last active April 24, 2017 15:40
Add two Custom Fields to be included on the SearchWP settings screen
<?php
function my_searchwp_custom_field_keys( $keys ) {
$keys[] = 'my_first_meta_key';
$keys[] = 'my_second_meta_key';
return $keys;
}
add_filter( 'searchwp_custom_field_keys', 'my_searchwp_custom_field_keys', 10, 1 );
@jchristopher
jchristopher / gist:7852755
Created December 8, 2013 02:44
Tell SearchWP to exclude certain post(s) when searching
<?php
function my_searchwp_exclude( $ids, $engine, $terms )
{
$ids[] = 78; // forcefully exclude post 78
return $ids;
}
add_filter( 'searchwp_exclude', 'my_searchwp_exclude', 10, 3 );
@jchristopher
jchristopher / gist:7861789
Created December 8, 2013 18:35
SearchWP allows you to filter the exact WHERE clause fired in the main search algorithm
<?php
function my_searchwp_where( $clause, $engine ) {
// manipulate $clause to your liking and return it
return $clause;
}
add_filter( 'searchwp_where', 'my_searchwp_where', 10, 2 );