Creating a custom event search form

Creating a custom event search form

WP Event Manager’s [Events] shortcode is coded to pick up search_location and search_keywords variables from the query string. Because of this, it’s easy to create a search form elsewhere on your site which posts to your events page.

How to Create a custom event search form

Here is an example form:

  1. <form method="GET" action="YOUR_EVENTS_PAGE_URL">
  2.   <p>
  3.     <label for="keywords">Keywords</label>
  4.     <input type="text" id="search_keywords" name="search_keywords" />
  5.   </p>
  6.   <p>
  7.     <label for="keywords">Location</label>
  8.     <input type="text" id="search_location" name="search_location" />
  9.   </p>
  10.   <p>
  11.     <label for="search_category">Category</label>
  12.     <select id="search_category" name="search_category">
  13.         <?php foreach ( get_event_listing_categories() as $cat ) : ?>
  14.             <option value="<?php echo esc_attr( $cat->term_id ); ?>"><?php echo esc_html( $cat->name ); ?></option>
  15.         <?php endforeach; ?>
  16.     </select>
  17.   </p>
  18.   <p>
  19.     <input type="submit" value="Search" />
  20.   </p>
  21. </form>

Replace YOUR_EVENTS_PAGE_URL with the URL to your events page (assuming filters are enabled) and the form will function.