Skip to content

Instantly share code, notes, and snippets.

Jon Christopher jchristopher

View GitHub Profile
@jchristopher
jchristopher / functions.php
Created Apr 19, 2019
Integrate Flatsome's live search with SearchWP
View functions.php
<?php
// Integrate Flatsome's live search with SearchWP.
function my_flatsome_searchwp_integration( $search_query, $args, $defaults ) {
if ( ! class_exists( 'SWP_Query' ) ) {
return $function;
}
$results = new SWP_Query( $args );
@jchristopher
jchristopher / functions.php
Created Apr 19, 2019
Tell SearchWP to index taxonomy term slugs alongside the taxonomy term name
View functions.php
<?php
// Tell SearchWP to index taxonomy term slugs alongside the taxonomy term name.
add_filter( 'searchwp_indexer_taxonomy_term_index_slug', '__return_true' );
@jchristopher
jchristopher / functions.php
Last active Apr 19, 2019
Index taxonomy term metadata alongside taxonomy term in SearchWP
View functions.php
<?php
// Index taxonomy term metadata alongside taxonomy term in SearchWP.
add_filter( 'searchwp_indexer_taxonomy_term', function( $to_index, $context ) {
$term_meta = get_term_meta( $context['term']->term_id, 'my_term_meta_key', true );
// If the metadata exists, append it to the string to be indexed by SearchWP.
return ! empty( $term_meta ) ? $to_index . ' ' . $term_meta : $to_index;
}, 10, 2 );
@jchristopher
jchristopher / functions.php
Created Apr 19, 2019
Add Markdown MIME type support in SearchWP
View functions.php
<?php
// Add Markdown MIME type support in SearchWP.
add_filter( 'searchwp_mimes_text', function( $mimes ) {
$mimes[] = 'text/markdown';
return $mimes;
} );
@jchristopher
jchristopher / functions.php
Created Apr 18, 2019
Customize SearchWP's white space threshold when indexing PDFs
View functions.php
<?php
// Allow PDFs with up to 10% white space to be indexed.
add_filter( 'searchwp_pdf_spaces_to_content_percentage', function( $percentage ) {
return 10;
} );
@jchristopher
jchristopher / functions.php
Created Apr 18, 2019
Enable PID output when debugging in SearchWP
View functions.php
<?php
// Enable PID output when debugging in SearchWP.
add_filter( 'searchwp_debug_include_pid', '__return_true' );
@jchristopher
jchristopher / functions.php
Created Apr 18, 2019
Customize SearchWP arguments when performing a search
View functions.php
<?php
// Customize SearchWP arguments when performing a search.
add_filter( 'searchwp_search_args', function( $args ) {
// $args['terms'] // The search terms for this request.
// $args['engine'] // The engine used for the search.
// $args['page'] // Which page of results to retrieve.
// $args['posts_per_page'] // How many posts per page to retrieve.
// $args['order'] // Sorting order of results (ASC or DESC).
// $args['load_posts'] // Whether to load the full WP_Post object for each result.
@jchristopher
jchristopher / functions.php
Created Apr 18, 2019
Prevent SearchWP from accepting a query string to accept results order
View functions.php
<?php
// Prevent SearchWP from accepting a query string to accept results order.
add_filter( 'searchwp_query_allow_query_string_override_order', '__return_false' );
@jchristopher
jchristopher / functions.php
Created Apr 18, 2019
Prevent incompatibility with SearchWP by removing all usage of pre_get_post during searches
View functions.php
<?php
// Prevent incompatibility with SearchWP by removing all usage of pre_get_post during searches.
add_filter( 'searchwp_remove_pre_get_posts_during_search', '__return_true' );
@jchristopher
jchristopher / functions.php
Created Apr 18, 2019
Prevent SearchWP from accepting an orderby query parameter
View functions.php
<?php
// Prevent SearchWP from accepting an orderby query parameter.
add_filter( 'searchwp_query_allow_query_string_override_orderby', '__return_false' );
You can’t perform that action at this time.