This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// In order to paginate randomized results, we need a seed. | |
add_action( 'init', function() { | |
if ( ! isset( $_COOKIE['seed'] ) ) { | |
setcookie( 'seed', rand(), 0, COOKIEPATH, COOKIE_DOMAIN ); | |
} | |
} ); | |
// Tell SearchWP to randomize the results based on the stored seed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Super simple transient storage of the 4 most recent Instagramp posts. | |
// Stores only images/first image in carousel album. | |
// Assumes you already have an access token. | |
// Don't know if the access token invalidates over time. If it does, this doesn't handle it. | |
// Transient storage is an array of media objects directly from Instagram. | |
// Possible to sideload images into the Media library using https://developer.wordpress.org/reference/functions/media_sideload_image/ | |
$transient_name = 'my_instagram_feed'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add Drafts to Products when indexing and searching in Admin. | |
add_filter( 'searchwp\post_stati\product', function( $stati ) { | |
$stati[] = 'draft'; | |
$stati[] = 'private'; | |
return $stati; | |
}, 30 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'searchwp\tokens', function( $tokens ) { | |
return array_filter( $tokens, function( $token ) { | |
return ! is_email( $token ); | |
} ); | |
}, 5 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'searchwp\query\mods', function( $mods ) { | |
if ( ! is_admin() ) { | |
return $mods; | |
} | |
if ( empty( $_GET['orderby'] || empty( $_GET['order'] ) ) { | |
return $mods; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add WooCommerce Product Variation data to parent Products in SearchWP. | |
add_filter( 'searchwp\entry\data', function( $data, \SearchWP\Entry $entry ) { | |
// If this is not a Product, there's nothing to do. | |
if ( 'product' !== get_post_type( $entry->get_id() ) ) { | |
return $data; | |
} | |
$my_extra_meta_key = 'searchwp_product_variations'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add relevance weight based on number of comments. | |
add_filter( 'searchwp\query\mods', function( $mods ) { | |
global $wpdb; | |
// Multiply the number of comments by this multiplier. | |
$comment_count_multiplier = 1; | |
$mod = new \SearchWP\Mod(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Customize ACF Relationship field data. By default an array of IDs is stored, | |
// this customization will instead tell SearchWP to index the full WP_Post object. | |
add_filter( 'searchwp\source\post\attributes\meta', function( $meta_value, $data ) { | |
$acf_field_names = [ | |
'acf_relationship_field_name_1', | |
'acf_relationship_field_name_2', | |
'acf_relationship_field_name_3', | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Tell SearchWP to parse WooCommerce Downloadable Product downloads for document content. | |
// The content will be extracted from downloadable documents where possible and stored | |
// in SearchWP's index as a Custom Field with a label of "SearchWP WooCommerce Download Content" | |
add_filter( 'searchwp\entry\data', function( $data, \SearchWP\Entry $entry ) { | |
if ( 'post.product' !== $entry->get_source()->get_name() || ! class_exists( 'WC_Product' ) ) { | |
return $data; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Force multiple word searches to use quoted search logic if quotes are not added. | |
// NOTE: Quoted search must be enabled (checkbox on the Advanced tab) | |
add_filter( | |
'searchwp\query\search_string', | |
function( $search_string, $query ) { | |
// If there are already quotes, bail out. | |
if ( false !== strpos( $search_string, '"' ) ) { | |
return $search_string; |