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 support for WooCommerce Admin filters when searching Orders with SearchWP. | |
add_filter( 'searchwp\query\mods', function( $mods, $query ) { | |
global $wpdb; | |
if ( isset( $_GET['_customer_user'] ) && ! empty( $_GET['_customer_user'] ) ) { | |
$mod = new \SearchWP\Mod( \SearchWP\Utils::get_post_type_source_name( 'shop_order' ) ); | |
$mod->set_local_table( $wpdb->postmeta ); | |
$mod->on( 'post_id', [ 'column' => 'id' ] ); |
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 | |
// Use Apache Tika to extract PDF content in SearchWP. | |
add_filter( 'searchwp\parser\pdf', function( $content, $args ) { | |
// Ensure this path is updated to match your Tika installation path! | |
$path_to_tika = '/srv/bin/tika-app-1.18.jar'; | |
// Execute the command. | |
$cmd = "java -jar {$path_to_tika} -t {$args['file']}"; |
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 | |
// Limit SearchWP Product searches to the first 30 characters of the Title. | |
add_filter( 'searchwp\entry\data', function( $data, $entry ) { | |
$source = \SearchWP\Utils::get_post_type_source_name( 'product' ); | |
if ( $source === substr( $entry->get_source()->get_name(), 0, strlen( $source ) ) ) { | |
$data['title'] = isset( $data['title'] ) ? substr( $data['title'], 0, 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 WooCommerce Order item data to WooCommerce Orders Search in SearchWP. | |
// @link https://searchwp.com/documentation/knowledge-base/search-woocommerce-orders/ | |
add_filter( 'searchwp\entry\data', function( $data, \SearchWP\Entry $entry ) { | |
// The Product data keys to index for each Order item. | |
$data_to_index = [ | |
'sku', | |
'name', | |
'slug', |
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 | |
// Remove parsed PDF content when rebuilding SearchWP index. | |
add_action( 'searchwp\index\rebuild', function() { | |
global $wpdb; | |
$wpdb->delete( $wpdb->prefix . 'postmeta', array( 'meta_key' => SEARCHWP_PREFIX . 'content' ) ); | |
$wpdb->delete( $wpdb->prefix . 'postmeta', array( 'meta_key' => SEARCHWP_PREFIX . 'pdf_metadata' ) ); | |
} ); |
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 private Custom Post Types to SearchWP. | |
add_filter( 'searchwp\sources', function( $sources ) { | |
// Create a Source from each private CPT e.g. | |
$sources[] = new \SearchWP\Sources\Post( 'my_private_cpt_name_1' ); | |
$sources[] = new \SearchWP\Sources\Post( 'my_private_cpt_name_2' ); | |
$sources[] = new \SearchWP\Sources\Post( 'my_private_cpt_name_3' ); | |
return $sources; |
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 | |
// Sort SearchWP Post, Page, and Custom Post Type Results by date in DESC order. | |
add_filter( 'searchwp\query\mods', function( $mods, $query ) { | |
foreach ( $query->get_engine()->get_sources() as $source ) { | |
$flag = 'post' . SEARCHWP_SEPARATOR; | |
if ( 'post.' !== substr( $source->get_name(), 0, strlen( $flag ) ) ) { | |
continue; | |
} |
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 | |
// @link https://searchwp.com/documentation/knowledge-base/append-document-content-to-parent-post-content/ | |
// Retrieve child PDF content and add as 'extra' data to a SearchWP Entry. | |
add_filter( 'searchwp\entry\data', function( $data, \SearchWP\Entry $entry ) { | |
// Convert the SearchWP Entry into it's native object type. | |
$entry = $entry->native(); | |
// We only want to consider WP_Post objects. | |
if ( ! $entry instanceof \WP_Post ) { |
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 | |
// @link https://searchwp.com/documentation/knowledge-base/comparing-index-source-mods/ | |
// Instantiate an index Mod that applies to the entire index. | |
$mod = new \SearchWP\Mod(); | |
// Instantiate a Source Mod that applies only to Posts. | |
$source = \SearchWP\Utils::get_post_type_source_name( 'post' ); | |
$mod = new \SearchWP\Mod( $source ); |
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 | |
// Drop Media from results that have no parent when parent attribution has been enabled in SearchWP. | |
// @link https://searchwp.com/documentation/hooks/searchwp-source-post-post_type-parent_attribution-strict | |
add_filter( 'searchwp\source\post\attachment\parent_attribution\strict', '__return_true' ); |