Skip to content

Instantly share code, notes, and snippets.

@jchristopher
jchristopher / gist:dc094a923dbfe8b9ad01
Created May 5, 2014 14:27
Set the search engine name for forms automatically enhanced by SearchWP Live Search
<?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:8cb5ecaeea8e400e2d14
Created May 5, 2014 14:49
Prevent the baseline SearchWP Live Search results positioning from showing (NOTE: this does not alter the theme (visual) styles)
<?php
add_filter( 'searchwp_live_search_base_styles', '__return_false' );
@jchristopher
jchristopher / gist:fba421486843f07f4c6d
Last active August 29, 2015 14:01
Integrate SearchWP with WP Document Revisions by indexing Revision content via SearchWP's Xpdf Integration extension (required) as a Custom Field named 'wp_document_revision'
<?php
// BEGIN WP Document Revisions/SearchWP integration (REQUIRES XPDF INTEGRATION EXTENSION)
// NOTE: after this snippet has been added to functions.php you will need to customize
// the Document weight on SearchWP's settings screen, adding a Custom Field with the
// name of 'wp_document_revision' and giving it the weight; that's where document
// content will be stored (as Custom Field content)
/**
@jchristopher
jchristopher / 0_reuse_code.js
Created May 28, 2014 20:29
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jchristopher
jchristopher / gist:cdb6130c994b9feec8cd
Created May 31, 2014 20:22
Replicate term whitelist exclusivity when searching in SearchWP (normally it's just when indexing)
<?php
function my_searchwp_search_regex_whitelist_exclusivity( $terms, $engine ) {
global $searchwp;
// we want to strip out any partial matches
$terms = ' ' . $terms . ' ';
$whitelisted_terms = $searchwp->extract_terms_using_pattern_whitelist( $terms );
$terms = str_replace( ' ', ' ', $terms );
@jchristopher
jchristopher / gist:791086f813d1d8920719
Last active August 29, 2015 14:02
Retrieve taxonomy terms in order of their post's post_date
<?php
global $wpdb;
$post_types = array( 'my_post_type' );
$taxonomy = array( 'my_taxonomy' );
$order = 'DESC';
$sql = "SELECT DISTINCT t.*
FROM $wpdb->terms AS t
@jchristopher
jchristopher / gist:10b586aa52b6c3721f28
Last active August 29, 2015 14:03
Integrate SearchWP with WP-Views Parametric Search
<?php
/**
* Tell WP Views Parametric Search to restrict it's results pool
* to what SearchWP finds, based on our custom setup
*/
// tell WP-Views to limit the results pool
function my_searchwp_wpvparametric( $query ){
@jchristopher
jchristopher / gist:6817e67604dd738bf47c
Last active August 29, 2015 14:03
Add a 'where will you be promoting ___' to AffiliateWP's registration form
<?php
// add a 'where will you be promoting ___' to AffiliateWP's registration form
add_action( 'affwp_register_fields_before_tos', function() {
?>
<p>
<label for="affwp-user-where">Where will you be promoting SearchWP? USE SPECIFIC URLs (e.g. websites, social networks, etc.)</label>
<textarea id="affwp-user-where" name="affwp-user-where"></textarea>
</p>
<?php
<?php
if ( class_exists( 'SOME_CLASS' ) ) {
// automatically deactivate
require_once ABSPATH . '/wp-admin/includes/plugin.php';
deactivate_plugins( __FILE__ );
wp_die( 'SRY :(' );
}
@jchristopher
jchristopher / gist:635c8a849cc469be6719
Last active August 29, 2015 14:03
SearchWP 2.3 will make available all of the weights that dictated the order of search results
<?php
print_r( SWP()->results_weights );
/* ===================== OUTPUT =====================
Primary array key is the $post->ID, each primary value contains the overall
weight for that $post in addition to the weight for each post type
Array