Skip to content

Instantly share code, notes, and snippets.

Jon Christopher jchristopher

Block or report user

Report or block jchristopher

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jchristopher
jchristopher / tmp.php
Created Mar 27, 2020
Check whether a SearchWP Engine has non-WP_Post Sources
View tmp.php
<?php
// Check whether a SearchWP Engine has non-WP_Post Sources.
$engine = new \SearchWP\Engine( 'supplemental' );
$sources = array_keys( $engine->get_sources() );
$non_wp_post_sources = array_filter( $sources, function( $source ) {
return 0 !== strpos( $source, 'post' . SEARCHWP_SEPARATOR );
} );
@jchristopher
jchristopher / searchwp-customizations.php
Created Mar 27, 2020
Custom SearchWP Source for BuddyPress Activity
View searchwp-customizations.php
<?php
/**
* Custom SearchWP Source for BuddyPress Activity.
* NOTE: Requires SearchWP 4
*/
add_action( 'plugins_loaded', function() {
if ( ! class_exists( '\SearchWP\Source' ) || ! function_exists( 'bp_activity_get' ) ) {
return;
}
@jchristopher
jchristopher / searchwp-customizations.php
Created Mar 27, 2020
Disable keyword stemming for all Engines in SearchWP
View searchwp-customizations.php
<?php
// Disable keyword stemming for all Engines in SearchWP.
add_filter( 'searchwp\query\tokens\use_stems', '__return_false' );
@jchristopher
jchristopher / searchwp-customizations.php
Created Mar 27, 2020
Accept up to 12 search terms in SearchWP
View searchwp-customizations.php
<?php
// Accept up to 12 search terms in SearchWP.
add_filter(
'searchwp\query\tokens\limit',
function( $max, $query ) {
return 12;
},
30, 2
);
@jchristopher
jchristopher / searchwp-customizations.php
Created Mar 27, 2020
Remove hyphens from product codes when searching in SearchWP
View searchwp-customizations.php
<?php
// Remove hyphens from product codes when searching in SearchWP.
add_filter(
'searchwp\query\search_string',
function( $search_string, $query ) {
return str_replace( '-', '', $search_string );
},
30, 2
);
@jchristopher
jchristopher / searchwp-customizations.php
Created Mar 27, 2020
Enable quoted search support in SearchWP
View searchwp-customizations.php
<?php
// Enable quoted search support in SearchWP.
add_filter(
'searchwp\query\logic\phrase',
function( $enabled, $query ) {
return false;
},
30, 2
);
@jchristopher
jchristopher / searchwp-customizations.php
Created Mar 27, 2020
Disable AND logic in SearchWP
View searchwp-customizations.php
<?php
// Disable AND logic in SearchWP.
add_filter(
'searchwp\query\logic\and',
function( $enabled, $query ) {
return false;
},
30, 2
);
@jchristopher
jchristopher / searchwp-customizations.php
Created Mar 27, 2020
Customize the results returned by SearchWP
View searchwp-customizations.php
<?php
// Customize the results returned by SearchWP.
add_filter(
'searchwp\query\results',
function( $results, $query ) {
// This is where you can manipulate the $results array of results.
return $results;
},
@jchristopher
jchristopher / searchwp-customizations.php
Created Mar 27, 2020
Load all Source Attribute data for SearchWP search results
View searchwp-customizations.php
<?php
// Load all Source Attribute data for SearchWP search results.
add_filter(
'searchwp\query\result\load_data\all_attributes',
function( $enabled, $args ) {
return true;
},
30, 2
);
@jchristopher
jchristopher / searchwp-customizations.php
Created Mar 27, 2020
Load Source Attribute data for SearchWP search results
View searchwp-customizations.php
<?php
// Load Source Attribute data for SearchWP search results.
add_filter(
'searchwp\query\result\load_data',
function( $enabled, $args ) {
return true;
},
30, 2
);
You can’t perform that action at this time.