Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created June 30, 2020 00:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jchristopher/4951b81c94724b1f62900bce0333bc69 to your computer and use it in GitHub Desktop.
Save jchristopher/4951b81c94724b1f62900bce0333bc69 to your computer and use it in GitHub Desktop.
Limit SearchWP Product searches to the first 30 characters of the Title
<?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 ) : '';
}
return $data;
}, 30, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment