Skip to content

Instantly share code, notes, and snippets.

<?php
function searchwp_custom_timeout()
{
return 25;
}
add_filter( 'swp_timeout', 'searchwp_custom_timeout' );
@jchristopher
jchristopher / gist:7312074
Last active August 12, 2020 02:43
Supplemental SearchWP search engine integration with Genesis, supports pagination
<?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>';
}
<?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 );
<?php
/**
* The template for displaying Search Results pages.
*
* @package WordPress
* @subpackage Twenty_Thirteen
* @since Twenty Thirteen 1.0
*/
get_header(); ?>
<?php
function myChangeDigitThreshold()
{
return 15; // 15% maximum threshold
}
add_filter( 'searchwp_fuzzy_digit_threshold', 'myChangeDigitThreshold' );
@jchristopher
jchristopher / gist:7491200
Last active March 8, 2019 15:03
Limit SearchWP results to a single category
<?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 April 26, 2019 14:33
Customize the list of stopwords SearchWP uses by adding your own custom words
<?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 November 20, 2013 15:40
Enable 'phrase synonyms' in SearchWP
<?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 November 21, 2013 13:14
Use searchwp_custom_field_keys in SearchWP to customize the Custom Fields listed on the Settings screen
<?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 November 21, 2013 18:24
Tell WordPress to leave Subscribers (only) logged in for one year
<?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' );