Skip to content

Instantly share code, notes, and snippets.

View gist:6830366
<?php
function searchwp_custom_timeout()
{
return 25;
}
add_filter( 'swp_timeout', 'searchwp_custom_timeout' );
@jchristopher
jchristopher / gist:7312074
Last active Aug 12, 2020
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 gist:7325390
<?php
function mySearchIncludeIds( $ids, $engine, $terms )
{
$ids = get_page_ids_user_can_access(); // returns array of post IDs that the user has access to
return $ids;
}
add_filter( 'searchwp_include', 'my_limit_search_results', 10, 3 );
View gist:7414211
<?php
/**
* The template for displaying Search Results pages.
*
* @package WordPress
* @subpackage Twenty_Thirteen
* @since Twenty Thirteen 1.0
*/
get_header(); ?>
View gist:7417970
<?php
function myChangeDigitThreshold()
{
return 15; // 15% maximum threshold
}
add_filter( 'searchwp_fuzzy_digit_threshold', 'myChangeDigitThreshold' );
@jchristopher
jchristopher / gist:7491200
Last active Mar 8, 2019
Limit SearchWP results to a single category
View gist:7491200
<?php
function searchwp_include_only_category( $ids, $engine, $terms ) {
// Limit to category 10
$categoryID = 10;
// Retrieve the IDs of all the posts in this category
$args = array(
'category' => $categoryID,
'fields' => 'ids',
@jchristopher
jchristopher / gist:7563164
Last active Apr 26, 2019
Customize the list of stopwords SearchWP uses by adding your own custom words
View gist:7563164
<?php
function my_searchwp_stopwords( $terms ) {
// add 'lorem', 'ipsum', and 'dolor' to SearchWP's default terms
$terms[] = 'lorem';
$terms[] = 'ipsum';
$terms[] = 'dolor';
return $terms;
}
@jchristopher
jchristopher / gist:7565207
Created Nov 20, 2013
Enable 'phrase synonyms' in SearchWP
View gist:7565207
<?php
function myPhraseSynonyms( $terms ){
// if the person searched for 'super hero' let's add 'superhero'
if( in_array( 'super', $terms ) && in_array( 'hero', $terms ) ) {
// remove 'super' and 'hero'
foreach( $terms as $key => $term ) {
if( $term == 'super' || $term == 'hero' ) {
@jchristopher
jchristopher / gist:7581383
Created Nov 21, 2013
Use searchwp_custom_field_keys in SearchWP to customize the Custom Fields listed on the Settings screen
View gist:7581383
<?php
function mySwpCustomFields( $keys ) {
// $keys is an array of Custom Field keys
// I want to add 'sku' to that list
$keys[] = 'sku';
// I need to return my customized array back to SearchWP
return $keys;
}
@jchristopher
jchristopher / gist:7586811
Created Nov 21, 2013
Tell WordPress to leave Subscribers (only) logged in for one year
View gist:7586811
<?php
function change_logged_in_duration( $expirein ) {
if( !current_user_can( 'edit_posts' ) ) {
return 31556926; // 1 year in seconds
}
}
add_filter( 'auth_cookie_expiration', 'change_logged_in_duration' );