Skip to content

Instantly share code, notes, and snippets.

Jon Christopher jchristopher

View GitHub Profile
@jchristopher
jchristopher / functions.php
Created Mar 21, 2019
Use SearchWP to make WooCommerce Downloadable Product Document content searchable
View functions.php
<?php
// Tell SearchWP to parse WooCommerce Downloadable Product downloads for document content.
// The content will be extracted from downloadable documents where possible
// and stored as extra metadata with a key of `swp_wc_doc_content`
add_filter( 'searchwp_extra_metadata', function( $extra_metadata, $the_post ) {
if ( 'product' !== get_post_type( $the_post ) || ! class_exists( 'WC_Product' ) ) {
return $extra_metadata;
}
@jchristopher
jchristopher / functions.php
Created Mar 20, 2019
Adjust the maximum weight in SearchWP's engine configuration UI
View functions.php
<?php
// Increase the maximum available SearchWP weight to 500
function my_searchwp_weight_max( $weight ) {
return 500;
}
add_filter( 'searchwp_weight_max', 'my_searchwp_weight_max' );
@jchristopher
jchristopher / functions.php
Created Mar 20, 2019
Prevent SearchWP from imposing its engine configuration on empty search requests
View functions.php
<?php
// Prevent SearchWP from imposing its engine configuration on empty search requests
add_filter( 'searchwp_disable_impose_engine_config', '__return_true' );
@jchristopher
jchristopher / functions.php
Last active Mar 14, 2019
Give extra weight to entries within a Category, Tag, or Taxonomy Term in SearchWP
View functions.php
<?php
function my_searchwp_weight_mods( $sql ) {
global $wpdb;
$swp_db_prefix = $wpdb->prefix . SEARCHWP_DBPREFIX;
// These are the taxonomy terms we want to give bonus weight.
$bonuses = array(
array(
View functions.php
<?php
/**
* Index WooCommerce Product Variations
*/
// Add product variations to the list of post types to index
function my_searchwp_indexed_post_types( $post_types ) {
if ( ! in_array('product_variation', $post_types ) ) {
$post_types = array_merge( $post_types, array( 'product_variation' ) );
@jchristopher
jchristopher / functions.php
Created Feb 17, 2019
SWP_Query Loop syntax
View functions.php
<?php
$swp_query = new SWP_Query( array( 's' => 'coffee' ) );
if ( $swp_query->have_posts() ) {
while ( $swp_query->have_posts() ) {
$swp_query->the_post();
get_template_part( 'content', 'search' );
}
} else {
@jchristopher
jchristopher / functions.php
Created Feb 17, 2019
Prevent SearchWP from parsing blocks during indexing
View functions.php
<?php
add_filter( 'searchwp_do_blocks', '__return_false' );
@jchristopher
jchristopher / functions.php
Created Feb 14, 2019
Customize meta content before it is highlighted in SearchWP
View functions.php
<?php
function my_searchwp_th_pre_process_meta_value( $meta_value, $meta_key, $post_id ) {
// TODO: Customize $meta_value where applicable.
return $meta_value;
}
add_filter( 'searchwp_th_pre_process_meta_value', 'my_searchwp_th_pre_process_meta_value', 10, 3 );
@jchristopher
jchristopher / functions.php
Created Feb 14, 2019
Customize which meta keys are used for highlighting when finding better excerpts
View functions.php
<?php
function my_searchwp_th_meta_keys( $meta_keys ) {
// TODO: update $meta_keys if necessary.
return $meta_keys;
}
add_filter( 'searchwp_th_meta_keys', 'my_searchwp_th_meta_keys' );
@jchristopher
jchristopher / functions.php
Created Feb 14, 2019
Customize content before SearchWP highlights it
View functions.php
<?php
function my_searchwp_th_pre_process_content( $content ) {
// TODO: manipulate $content in any way you'd like.
return $content;
}
add_filter( 'searchwp_th_pre_process_content', 'my_searchwp_th_pre_process_content' );
You can’t perform that action at this time.