Skip to content

Instantly share code, notes, and snippets.

Jon Christopher jchristopher

View GitHub Profile
@jchristopher
jchristopher / functions.php
Created Apr 16, 2019
Tell SearchWP to index the Title from a Relationship ACF field
View functions.php
<?php
/**
* Tell SearchWP to index the Title from a Relationship ACF field.
*/
function my_searchwp_read_next_field( $meta_value, $meta_key, $the_post ) {
$acf_field_name = 'read_next'; // The ACF Relationship field name.
// If we're not indexing the Read Next field, return the existing meta value.
// This logic also works for sub-fields of an ACF field as well.
@jchristopher
jchristopher / functions.php
Last active Apr 15, 2019
Prevent EDD Software Licensing Recurring renewal when associated subscription is failing
View functions.php
<?php
// Prevent license renewal when associated subscription is failing
// (it will cause double charges and double subscriptions and waste a lot of your time)
add_action( 'edd_pre_add_to_cart', function( $download_id, $options ) {
// Only applicable if this is a renewal.
if ( empty( $options['is_renewal'] ) ) {
return;
}
@jchristopher
jchristopher / searchwp-windows-compat.php
Created Mar 29, 2019
SearchWP Windows Update Compatibility
View searchwp-windows-compat.php
<?php
/**
* Plugin Name: SearchWP Windows Server Compatibility
* Plugin URI: https://searchwp.com/docs/kb/an-error-occurred-while-updating-searchwp-could-not-create-directory/
* Description: Resolves an issue on Windows servers that prevents SearchWP from automatically updating.
*/
/**
* @link https://gist.github.com/spivurno/d7a93ab4920c4fa88bad0e5177b45ba1
* Easy Digital Downloads provides packages URLs that look something like this:
@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' );
You can’t perform that action at this time.