Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Created December 28, 2023 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrasguseo/fb4641b0b07124963e10c40c4dfa9dfc to your computer and use it in GitHub Desktop.
Save andrasguseo/fb4641b0b07124963e10c40c4dfa9dfc to your computer and use it in GitHub Desktop.
TEC > Transform all single quotes and apostrophes to straight single quotes in search string.
<?php
/**
* Transform all single quotes and apostrophes to straight single quotes in search string.
*
* Usage: Add the snippet to your functions.php file or with a plugin like Code Snippets
*
* Plugins required: The Events Calendar
* Author: Andras Guseo
* Created: December 28, 2023
*/
function tec_search_filter_transform_single_quotes( $query ) {
// Bail if not search or on admin.
if ( ! $query->is_search || is_admin() ) {
return $query;
}
if ( $query->get( 'post_type' ) == 'tribe_events' ) {
$search_phrase = $query->get( 's' );
$search_phrase = str_replace( [ "'", "‘", "’", "‛" ], "'", $search_phrase );
$query->set( 's', $search_phrase );
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment