Title: [Plugin: Events Manager] Using Search with this plugin
Last modified: August 19, 2016

---

# [Plugin: Events Manager] Using Search with this plugin

 *  Resolved [Daniel Payne](https://wordpress.org/support/users/djepayne/)
 * (@djepayne)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-events-manager-using-search-with-this-plugin/)
 * I’m using this plugin and wanted to know how do I connect the Search feature 
   to the custom database table fields?
 * Would the approach written about [in the Codex](http://codex.wordpress.org/Custom_Queries)
   add Search to Event Manager?
 * Thanks again.
 * [http://wordpress.org/extend/plugins/events-manager/](http://wordpress.org/extend/plugins/events-manager/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [Daniel Payne](https://wordpress.org/support/users/djepayne/)
 * (@djepayne)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-events-manager-using-search-with-this-plugin/#post-1736010)
 * Instead of the Codex approach I just updated my search.php file and placed the
   following code above the loop:
 *     ```
       mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
       @mysql_select_db(DB_NAME) or die( "Unable to select database");
       $table = $table_prefix."em_events";
       $s = $_REQUEST['s']; // The search key words
       $found_event = false;
   
       $query = "SELECT * FROM $table WHERE (event_name LIKE '%".$s."%') OR
       (event_notes LIKE '%".$s."%') ORDER BY event_start_date";
       $result = mysql_query($query) or die(mysql_error());
   
       while($row = mysql_fetch_array($result)) { // Found some matches
       	print "<h2><a href='".get_bloginfo('url')."/events/?event_id=".$row['event_id']."'>".$row['event_name']."</a> ".$row['event_start_date']."</h2>";
       	print substr($row['event_notes'],0,250)."[...]";
       	print "<div style='clear:both;'></div>";
       	$found_event = true;
       }
       ```
   
 *  Plugin Author [Marcus (aka @msykes)](https://wordpress.org/support/users/netweblogic/)
 * (@netweblogic)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-events-manager-using-search-with-this-plugin/#post-1736136)
 * [@djepayne](https://wordpress.org/support/users/djepayne/)
 * Thanks for the link, will look into that!
 *  Thread Starter [Daniel Payne](https://wordpress.org/support/users/djepayne/)
 * (@djepayne)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-events-manager-using-search-with-this-plugin/#post-1736257)
 * Based on feedback I’ve updated the PHP code to use more WordPress built-in functions:
 *     ```
       $table = $wpdb->prefix."em_events";
       $s = mysql_real_escape_string($_REQUEST['s']); // The search key words
   
       $found_event = false;
   
       $query = "SELECT * FROM $table WHERE (event_name LIKE '%".$s."%') OR
       (event_notes LIKE '%".$s."%') ORDER BY event_start_date";
       $events = $wpdb->get_results ( $query, ARRAY_A );
       foreach ($events as $row) {
               print "<h2><a href='".get_bloginfo('url')."/events/?event_id=".$row['event_id']."'>".$row['event_name']."</a> ".$row['event_start_date']."</h2>";
               print substr($row['event_notes'],0,250)."[...]";
               print "<div style='clear:both;'></div>";
               $found_event = true;
       }
       ```
   
 *  Plugin Author [Marcus (aka @msykes)](https://wordpress.org/support/users/netweblogic/)
 * (@netweblogic)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-events-manager-using-search-with-this-plugin/#post-1736261)
 * we’ll add a search feature eventually that’ll shave off a few lines of code here.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘[Plugin: Events Manager] Using Search with this plugin’ is closed to 
new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=3550347)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Marcus (aka @msykes)](https://wordpress.org/support/users/netweblogic/)
 * Last activity: [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-events-manager-using-search-with-this-plugin/#post-1736261)
 * Status: resolved