You are here: Home / About us / Beetle blog & news / Wordpress Event Manager plugin - adding custom event attribute

Wordpress Event Manager plugin - adding custom event attribute

by Gordon Adams last modified Aug 05, 2014 01:52 PM
Event Manager is good. In fact it is bloody good. Adding custom attributes to events is easy and well documented. However how to make these new fields searchable is a little more less obviously documented. Here's how I did it...

How to add an new Event Attribute Teacher to the events page and make it searchable.

I added the new attribute "Teacher" with allowed values "Abi" and "Lou" to the EM Events listing and single event pages. This bit is straight forward so not much detail required...

  1. First add the new attribute and its allowed values with
    Events | Settings | General 
    Event Attributes : #_ATT{teacher}{Abi|Lou} 
    It can now be added to events.
  2. Next add the attribute (and appropriate headings) to the templates in
    Settings | Formatting | Events.
    Both the default event list and Singel Event page templates were tweaked.
    It will now be displayed in Events.

Here's the meat. How to use this new attribute in the EM search form. Customise as you wish. I used the add themes functions.php method...

// START EM Custm Attribute "Teacher" search
/* Create a new search attribute form entry for our new Event Attribute "teacher" (#_ATT{teacher})
The values are hard-coded but could probably be automatically selected
Add this field to the search form using an EM action.
nb. The action doc'd here
does not seem to exist so use the footer one for inclusion in advanced search or the header one
for normal search. Read the source Luke.
function my_teacher_search_field(){ ?>
<div class="em-search-teacher em-search-field">
<select name="teacher">
<option value=''>All Teachers</option>
<option value="Abi" <?php echo ((array_key_exists('teacher', $_POST)) && $_POST['teacher'] == "Abi") ? 'selected="selected"':''; ?>>Abi</option>
<option value="Lou" <?php echo ((array_key_exists('teacher', $_POST)) && $_POST['teacher'] == "Lou") ? 'selected="selected"':''; ?>>Lou</option>
<?php }
add_action('em_template_events_search_form_footer', 'my_teacher_search_field');
/* Hook the new search attribute teacher into default search filter,
so it isn’t ignored when Events Manager creates an events search query
function my_teacher_search($searches, $array){
if( !empty($array['teacher']) ){
$searches['teacher'] = $array['teacher'];
return $searches;

/* This isn't needed. It seems that inclusion in the default_search filter
is all thats needed. See
//function my_teacher_accepted_searches($searches){
// $searches[] = 'teacher';
// return $searches;

/* Can't hook into em_events_get filter as doc'd here
as we need to join with kal_postmeta and not just filter kal_em_events
so append a subquery via sql_conditions hook to find kal_postmeta using our new search attribute and return valid
posts ids for main event query that is internally appended to display.
function my_teacher_conditions($conditions, $args){
if( !empty($args['teacher'])) {
$teacherval = $args['teacher'];
$conditions['teacher'] = " (kal_em_events.post_id IN ( SELECT post_id FROM kal_postmeta WHERE (kal_postmeta.meta_key = 'teacher' AND kal_postmeta.meta_value = '$teacherval')))";
return $conditions;
add_filter( 'em_events_build_sql_conditions', 'my_teacher_conditions',1,2);
// END EM Custom Attribute Teacher Search