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 / gist:0caa9d0f14e7e80bec95
Created Feb 25, 2015
Limit SearchWP results to a specific post type
View gist:0caa9d0f14e7e80bec95
<?php
function my_searchwp_limit_to_post_type( $clause, $engine ) {
global $wpdb;
if ( isset( $_GET['post_type'] ) ) {
$post_type = sanitize_text_field( $_GET['post_type'] );
if ( post_type_exists( $post_type ) ) {
$clause = $wpdb->prepare( "AND {$wpdb->prefix}posts.post_type = %s", $post_type );
}
@jchristopher
jchristopher / gist:7312074
Last active Oct 30, 2019
Supplemental SearchWP search engine integration with Genesis, supports pagination
View gist:7312074
<?php
/* Template Name: Genesis and SearchWP integration with pagination */
function prefix_searchwp_form( $query ) {
echo '<form class="searchwp-form" action="" method="get">';
echo '<input type="text" id="searchwpquery" name="searchwpquery" value="' . esc_attr( $query ) . '" />';
echo '<button type="submit">' . __( 'Search', 'text-domain' ) . '</button>';
echo '</form>';
}
View functions.php
<?php
function my_searchwp_engine_settings_default( $settings, $query ) {
if ( empty( $_REQUEST['post_type'] ) ) {
return $settings;
}
$post_type_limiter = $_REQUEST['post_type'];
@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
Better control SearchWP during WP All Import import routine https://searchwp.com/docs/kb/best-work-content-imports/
View functions.php
<?php
/**
* WP All Import SearchWP PRE-import routine
*
* @link https://searchwp.com/docs/kb/best-work-content-imports/
*/
function myswp_before_xml_import( $import_id ) {
// Pause the SearchWP indexer during import
SWP()->indexer_pause();
@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;
}
You can’t perform that action at this time.