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:10211284
Last active Aug 29, 2015
Use SearchWP in conjunction with Dave's WordPress Live Search. To utilize, add the following to your theme's functions.php and save yourself the trouble of editing the plugin files.
View gist:10211284
<?php
function my_searchwp_dwls_alter_results( $search_results, $deprecated, $daves_live_search ) {
global $wp_query;
if( class_exists( 'SearchWP' ) ) {
// remove Dave's pre_get_posts
remove_action( 'pre_get_posts', array( 'DavesWordPressLiveSearchResults', 'pre_get_posts' ) );
View gist:10404359
<?php get_header(); ?>
<?php
$number_of_feature_posts = 1;
$number_of_secondary_posts = 8;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$how_many_secondary_posts_past = ($number_of_secondary_posts * ($paged - 1));
$off = $number_of_feature_posts + (($paged > 1) ? $how_many_secondary_posts_past : 0);
?>
View gist:10477709
<?php
// add support for strings like M&M in SearchWP
function my_searchwp_term_pattern_whitelist( $patterns ) {
$patterns[] = "/\\b([[:alnum:]]+\\s?(?:&\\s?[[:alnum:]]+)+)/is";
}
add_filter( 'searchwp_term_pattern_whitelist', 'my_searchwp_term_pattern_whitelist' );
@jchristopher
jchristopher / gist:10730056
Created Apr 15, 2014
Throttle the SearchWP indexer
View gist:10730056
<?php
// pause the indexer for 1s in between passes
function my_searchwp_indexer_throttle() {
return 1;
}
add_filter( 'searchwp_indexer_throttle', 'my_searchwp_indexer_throttle' );
View gist:11054399
<?php
/* Template Name: Advance Search Template */
global $post;
// retrieve our search query if applicable
$query = isset( $_REQUEST['swpquery'] ) ? sanitize_text_field( $_REQUEST['swpquery'] ) : '';
// retrieve our pagination if applicable
View keybase.md

Keybase proof

I hereby claim:

  • I am jchristopher on github.
  • I am jchristopher (https://keybase.io/jchristopher) on keybase.
  • I have a public key whose fingerprint is C446 E843 8699 4276 7D70 3CF4 5C0A BFF4 8230 0414

To claim this, I am signing this object:

View gist:11408704
<?php
function my_admin_notices() {
$success = true;
if( $success ) {
?>
<div class="updated">
<p><?php _e( '<strong>SUCCESS</strong> Success!', 'mytextdomain' ); ?></p>
</div>
<?php
@jchristopher
jchristopher / gist:2c635560de32191da7a5
Created Apr 30, 2014
If you're using get_search_form() to generate a search form on bbPress Forum, Topic, or Reply pages and want to limit search results to the current Forum, use this snippet
View gist:2c635560de32191da7a5
<?php
function my_get_search_form( $html ) {
// we need to append the current Forum ID so our future hook can use it
if( function_exists( 'bbp_get_forum_id' ) ) {
$forum_id = isset( $_REQUEST['swpforumid'] ) ? absint( $_REQUEST['swpforumid'] ) : bbp_get_forum_id();
if( ! empty( $forum_id ) ) {
$html = str_replace( '</form>', '<input type="hidden" name="swpforumid" value="' . $forum_id . '" /></form>', $html );
}
}
@jchristopher
jchristopher / gist:dc094a923dbfe8b9ad01
Created May 5, 2014
Set the search engine name for forms automatically enhanced by SearchWP Live Search
View gist:dc094a923dbfe8b9ad01
<?php
// only applies when SearchWP is active
function my_searchwp_live_search_get_search_form_engine() {
return 'my_supplemental_engine';
}
add_filter( 'searchwp_live_search_get_search_form_engine', 'my_searchwp_live_search_get_search_form_engine' );
@jchristopher
jchristopher / gist:226c751aab6993a04385
Last active Aug 29, 2015
Enable SearchWP Live Search on any search form input manually
View gist:226c751aab6993a04385
<?php
// if your form is generated using get_search_form() you do not need to do this
// as SearchWP Live Search does it automatically out of the box
?>
<form action="" method="get">
<p>
<label for="s"><?php _e( 'Search' , 'mytextdomain' ); ?></label>
<input type="text" name="s" id="s" value="" data-swplive="true" /> <!-- data-swplive="true" enables SearchWP Live Search -->
</p>
You can’t perform that action at this time.