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/v3/docs/kb/adding-metrics-link-tracking-to-listify-via-facetwp/ | |
// Add these lines BEFORE the existing template code. | |
do_action( 'searchwp_metrics_click_tracking_start' ); | |
add_action( 'listify_output_results', function() { | |
do_action( 'searchwp_metrics_click_tracking_stop' ); | |
} ); |
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 child PDF snippets to SearchWP result excerpt. | |
add_filter( 'get_the_excerpt', function( $excerpt ) { | |
global $post; | |
if ( ! $post instanceof WP_Post || ! is_search() || post_password_required() || $post->searchwp_excerpt_found ) { | |
return $excerpt; | |
} |
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 a Custom Field as a buoy to supercede SearchWP's relevance weight sorting. | |
add_filter( 'searchwp\query\mods', function( $mods, $query ) { | |
global $wpdb; | |
$meta_key = 'my_buoy_meta_key'; | |
// Add the buoy to these post types: | |
$post_types = [ 'post', 'page', ]; |
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 native WordPress search form to include current bbPress Forum ID if applicable. | |
add_filter( 'get_search_form', function( $markup ) { | |
if ( ! function_exists( 'bbp_get_forum_id' ) ) { | |
return $markup; | |
} | |
$forum_id = isset( $_REQUEST['swpforumid'] ) ? absint( $_REQUEST['swpforumid'] ) : bbp_get_forum_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 | |
// Add a Shortcode to exclude content from SearchWP's index. | |
add_shortcode( 'searchwp_no_index', function( $atts, $content = null ) { | |
// If the indexer is running do not return anything, | |
// else return the content contained in the Shortcode. | |
return did_action( 'searchwp\indexer\batch' ) ? '' : $content; | |
} ); |
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 | |
$highlighter = new \SearchWP\Highlighter(); | |
$haystack = 'The best coffee you can find!'; | |
$needle = 'coffee'; | |
// Output: | |
// The best <mark class="searchwp-highlight">coffee</mark> you can find! | |
echo $highlighter->apply( $haystack, $needle ); |
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/v3/docs/kb/using-elementor-for-supplemental-engines/ | |
// We need to flag the search form. | |
add_action( 'elementor_pro/search_form/after_input', function( $form ) { | |
// Check to see if this is the right Search Form. | |
$settings = $form->get_data( 'settings' ); |
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 | |
// @deprecated | |
// @see https://searchwp.com/documentation/hooks/searchwp-background_process-http_basic_auth_credentials/ | |
class MySearchWPBasicAuthCreds { | |
private $username = 'username'; // HTTP Basic Auth username. | |
private $password = 'password'; // HTTP Basic Auth password. | |
function __construct() { | |
// Provide HTTP Basic Authentication credentials to SearchWP. |
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/woocommerce-product-variation-skus/ | |
// Index WooCommerce Product Variation SKUs alongside the parent Product. | |
add_filter( 'searchwp\entry\data', function( $data, \SearchWP\Entry $entry ) { | |
$entry = $entry->native(); | |
if ( ! $entry instanceof \WP_Post || 'product' !== get_post_type( $entry ) ) { | |
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 | |
// Add bonus weight from Custom Field value in SearchWP. | |
add_filter( 'searchwp\query\mods', function( $mods ) { | |
global $wpdb; | |
// Custom Field name. Needs to store data as YYYYMMDD (ACF does this already). | |
$my_meta_key = 'date_field'; | |
$mod = new \SearchWP\Mod(); |