• Hy,

    I would like to add another search field.
    With event attributes

    Found this guide
    https://www.beetlebrow.co.uk/about-us/beetle-blog/wordpress-event-manager-plugin-adding-custom-event-attribute

    I think the variable or the code is outdated.
    Since no results will be given.

    Can anyone read times about the code, which is possibly wrong?
    Gladly a cafe donation for the finder,)

    Many Thanks

    <?php
    
     // 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 https://wp-events-plugin.com/tutorials/adding-custom-event-search-form-fields/
     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">
     <label>Test</label>
     <select name="teacher">
     <option value=''>Alle</option>
     <option value="Abi" <?php echo ((array_key_exists('teacher', $_POST)) && $_POST['teacher'] == "Abi") ? 'selected="selected"':''; ?>>Open</option>
     <option value="Lou" <?php echo ((array_key_exists('teacher', $_POST)) && $_POST['teacher'] == "Lou") ? 'selected="selected"':''; ?>>close</option>
     </select>
     </div>
     <?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;
     }
     add_filter('em_events_get_default_search','my_teacher_search',1,2);
    
     /* This isn't needed. It seems that inclusion in the default_search filter
     is all thats needed. See https://wp-events-plugin.com/tutorials/adding-custom-event-search-form-fields
     */
     //function my_teacher_accepted_searches($searches){
     // $searches[] = 'teacher';
     // return $searches;
     //}
     //add_filter('em_accepted_searches','my_teacher_accepted_searches',1,1);
    
     /* Can't hook into em_events_get filter as doc'd here
     https://wp-events-plugin.com/tutorials/creating-custom-event-search-attributes/
     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
    
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘adding custom event attribute in search’ is closed to new replies.