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
Created Oct 14, 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
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' );
@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
Created Sep 24, 2019
Implement aggressive Synonym handling in SearchWP 3.1+
View functions.php
<?php
add_filter( 'searchwp_synonyms_aggressive', '__return_true' );
@jchristopher
jchristopher / functions.php
Created Sep 23, 2019
Sort SearchWP results by multiple (3) numeric Custom Field post meta values
View functions.php
<?php
add_filter( 'searchwp_query_main_join', function( $sql, $engine ) {
global $wpdb;
$priority_1_meta_key = 'featured_meta_key';
$priority_2_meta_key = 'secondary_meta_key';
$priority_3_meta_key = 'tertiary_meta_key';
$sql = $sql . " LEFT JOIN {$wpdb->postmeta} swpprimary ON {$wpdb->posts}.ID = swpprimary.post_id AND swpprimary.meta_key = '{$priority_1_meta_key}'";
You can’t perform that action at this time.