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 / functions.php
Last active Oct 24, 2019
Override SearchWP's "Did you mean?" output
View functions.php
<?php
// Override SearchWP's "Did you mean?" output.
class MySearchwpDidYouMean {
private $args;
function __construct() {
// Prevent SearchWP's automatic "Did you mean?" output.
add_filter( 'searchwp_auto_output_revised_search_query', '__return_false' );
@jchristopher
jchristopher / functions.php
Last active Oct 22, 2019
Tell SearchWP to give bonus weight to results based on a Custom Field that stores a date (more recent gets more weight)
View functions.php
<?php
/**
* Tell SearchWP to give extra weight to results based on a date stored as a Custom Field
* value. The more recent the date the more bonus weight is given. The Custom Field value
* in the database needs to be UNIX_TIMESTAMP()-compatible (e.g. YYYYMMDD) which Advanced
* Custom Fields does by default.
*
* Customize $date_meta_key to be that of your meta_key and adjust the modifier to your liking.
*/
@jchristopher
jchristopher / functions.php
Last active Oct 15, 2019
Shortcode to disable default output SearchWP "Did you mean?" and add your own
View functions.php
<?php
class MySearchwpElementorDidYouMean {
private $args;
function __construct() {
add_filter( 'searchwp_auto_output_revised_search_query', '__return_false' );
add_action( 'searchwp_revised_search_query', function( $args ) {
$this->args = $args;
View functions.php
<?php
/**
* Tell SearchWP that it can index WooCommerce Orders.
*/
add_filter( 'searchwp_indexed_post_types', function( $post_types ) {
if ( ! is_array( $post_types ) ) {
$post_types = (array) $post_types;
}
View functions.php
<?php
// BETA implementation of bubbling exact matches to the top when partial matching is enabled in SearchWP
add_filter( 'searchwp_weight_mods', function( $sql ) {
global $wpdb;
$partial_matches_enabled = searchwp_get_setting_advanced( 'partial_matches' );
if ( empty( $partial_matches_enabled ) ) {
return $sql;
@jchristopher
jchristopher / functions.php
Last active Oct 4, 2019
Compatibility for AE Pro search results to prevent it from overriding SearchWP's results
View functions.php
<?php
// Compatibility for AE Pro search results to prevent it from overriding SearchWP's results.
add_filter( 'posts_pre_query', function( $posts, $wp_query ) {
if ( did_action( 'ae_pro_search' ) && $wp_query->is_search() ) {
$posts = array_keys( SWP()->results_weights );
$wp_query->found_posts = SWP()->foundPosts;
$wp_query->max_num_pages = SWP()->maxNumPages;
}
@jchristopher
jchristopher / functions.php
Created Sep 25, 2019
Output a custom notice when SearchWP finds a search correction
View functions.php
<?php
// Output a custom notice when SearchWP finds a search correction.
add_action( 'searchwp_revised_search_query', function( $args ) {
// TODO: Output a notice indicating a search correction has been made.
});
@jchristopher
jchristopher / functions.php
Created Sep 25, 2019
Prevent SearchWP from outputting notice about search query corrections
View functions.php
<?php
// Prevent SearchWP from outputting notice about search query corrections.
add_filter( 'searchwp_auto_output_revised_search_query', function( $enabled, $args ) {
// $args contains the search query arguments for the search
// $args['type'] will be 'did-you-mean' for "Did you mean?" corrections
return false;
} );
@jchristopher
jchristopher / functions.php
Created Sep 25, 2019
Programmatically enable "Did you mean?" search corrections in SearchWP 3.1+
View functions.php
<?php
// Enables "Did you mean?" search corrections in SearchWP.
add_filter( 'searchwp_do_suggestions', function( $enabled, $args ) {
// $args contains the search arguments.
return true;
} );
@jchristopher
jchristopher / functions.php
Last active Sep 25, 2019
Programmatically enable quoted search support in SearchWP 3.1+
View functions.php
<?php
// Enables quoted search support in SearchWP.
add_filter( 'searchwp_allow_quoted_phrase_search', '__return_true' );
You can’t perform that action at this time.