Events Made Easy Forums How do I … include contact name (and possibly more fields) in eme_wordpress_search_events()


Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #64306

    Hey Franky,

    So I’ve successfully added EME Events to the WordPress search functionality, as you’ve described in the FAQ and the Function API doc.
    Works like a charm, and I even managed to include my more elaborate event listing template using these three lines

    $body_format=eme_get_template_format_plain(79); // template 79 is our default event list template
       $body=eme_replace_placeholders($body_format, $event, "html");   
    print "<div class='eme_events_list'>.$body.'</div>'";

    Really neat.

    I understand the eme_wordpress_search_events() function looks for the search term in the title and description, right? We are making heavy use of the event contact name throughout (as well as some associated custom fields) and, therefore, people probably would expect to find results when they search for contact names as well.
    I was wondering if there is a way to include those fields in the search functions as well? I looked at the eme_wordpress_search_events() function, but, not being an PHP / SQL expert, it went a little over my head.
    Could you perhaps give me some pointers how and where to start and how I would be able to do this?

    Thank you!

    PS: I even managed to integrate the EME search in the Divi theme, which doesn’t come with a search.php file. I’d be happy to share this here in the forum for other Divi users to find. Not sure what the best place for this might be?


    Well, searching on the contact name for events requires searching in the wordpress tables while cross-referencing the EME events table on the value of event_contactperson_id . So you’d first need to get all used event_contactperson_id (for future events I guess) and then search WP persons for the info, limiting to those id’s. For the second part, see the function eme_get_wp_users as a start (which in fact uses the wordpress function WP_User_Query ).
    Also, to hook that into the wordpress search result: see eme_add_events_locations_link_search in eme_actions.php (and how it hooks into wp_link_query, also in that file).

    Concerning your Divi-theme howto: feel free to post that in the “Tips” forum:


    Thank you for suggestions. But I think that was not exactly what I was after, sorry for not being entirely clear.
    But I did some more thinking, research and a trial-and-error on my own and have come up with a working solution. I share the basic steps here, perhaps other people in a similar situation might find this useful. Basically, I created my own EME search function that I inserted into the search.php template and not using the eme_wordpress_search_events function anymore.
    Maybe you could give feedback, if this is way too hacky and/or could or should be improved so that I don’t run into any troubles on the long run.

    So here goes:

    1. First, I get all the relevant events with eme_get_events(0, $event_scope , "ASC", 0, "", $event_categoryIDs)

    2. Then I loop through the events, doing three things for each event:

    a) Construct a long string from all relevant event data I’m interested in. I find it easiest for me to do this with the EME placeholders, like so:
    $data_tags="#_EVENTID||#_CONTACTFULLNAME #_CONTACTFIELD{13} #_CONTACTFIELD{12} #_CONTACTFIELD{7}[eme_if tag='#ESC_EVENTCATEGORYIDS' eq=1][eme_if2 tag='#ESC_FIELDVALUE{17}' eq='1+2']Session 1 & 2 Tuesday 23/08 Wednesday 24/08 Friday 26/08 Saturday 27/08[/eme_if2][eme_if2 tag='#ESC_FIELDVALUE{17}' eq='1']Session 1 only Tuesday 23/08 Wednesday 24/08[/eme_if2][eme_if2 tag='#ESC_FIELDVALUE{17}' eq='2']Session 2 only Friday 26/08 Saturday 27/08[/eme_if2][/eme_if][eme_if tag='#ESC_EVENTCATEGORYIDS' eq=2][eme_if2 tag='#ESC_FIELDVALUE{18}' contains=':00|0']Tuesday 23/08 Wednesday 24/08 Thursday 25/08 Friday 26/08 Saturday 27/08 [/eme_if2][/eme_if][eme_if tag='#ESC_EVENTCATEGORYIDS' ne=1]#_STARTDATE{l d/m}[/eme_if] #_EVENTCATEGORIES #_FIELDVALUE{4} #_FIELD{6} [eme_if tag='#ESC_EVENTCATEGORYIDS' eq=9][eme_if2 tag='#ESC_24HSTARTTIME' eq='07:00']Morning[/eme_if2][eme_if2 tag='#ESC_24HSTARTTIME' ne='07:00']Evening[/eme_if2][/eme_if] #_NOTES";

    Then I run the $event_data = eme_replace_placeholders($data_tags, $event, "text") function.
    Might be a little hacky but it seems to work quite nicely.

    b) Check the $event_data for the search term(s) using preg_match($pattern, strtolower($event_data) whereby the $pattern is constructed as desribed here

    c) If the search terms are found, I write the event data to an $events array that holds all the matched events, using $events[] = eme_get_event($event_id);

    3. Now print the event information out to the user, using the loop you described in the FAQ (which I tweaked a little to use an EME template as described in my first post)
    I also added a “nothing found” message at the end of the EME section with <?php else: ?>


    The search.php How-to for Divi is very easy once you know how. I added it to the Tips section… Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.