Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Created December 21, 2020 13:25
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/d653af9b1d9a9ac092c1e13bf29a5858 to your computer and use it in GitHub Desktop.
Save andrasguseo/d653af9b1d9a9ac092c1e13bf29a5858 to your computer and use it in GitHub Desktop.
TEC: Excludes the event description and excerpt fields from the search
<?php
/* Description: Excludes the event description and excerpt fields from the search.
* Usage: Paste the below snippet into your active (child) theme's functions.php file
*
* Plugin: The Events Calendar
* Author: Barry Hughes, Andras Guseo
* Last updated: 2020-12-21
*/
function modify_event_searches( $search, WP_Query $wp_query ) {
if ( empty( $search ) ) return;
global $wpdb;
$new_search = preg_replace( "/{$wpdb->posts}.post_(content|excerpt) LIKE ('[{}a-zA-Z0-9]+')/", "0", $search );
return $new_search;
}
add_action( 'posts_search', 'modify_event_searches', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment