Events Made Easy Forums How do I … How do I find events and locations in the editor's link menu?

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #58111
    Anonymous
    Inactive

    The WP editor offers the link menu to easily add links to the texts and has the search function to link to existing posts and pages. Is there a way to insert EME events and locations in this search?

    #58115
    Franky
    Keymaster

    Hooking into wp_link_query can work maybe … to test …

    #58119
    Anonymous
    Inactive

    With this key word I found this https://gist.github.com/carasmo/133d33a98ee66171df9132ec0f2168c7

    Also a nice thing to have. But with my leaking knowledge and understanding I am not sure if and how I should continue now. Would you give me a hint please how to go further?

    #58121
    Franky
    Keymaster

    Hooks in wordpress are explained by wordpress 🙂
    But, read the eme FAQ on “How to add events to your wordpress search results?”, which is partly related (also a hook etc …). The only thing there is: I use a function called eme_wordpress_search_events(), and that function might need some tweaking for the url-search you want (if not the same POST param is used). Also, no time now, but I don’t know if there’s a eme_wordpress_search_locations() function too … and you need (as url) to use the functions eme_event_url($event) and eme_location_url($location) and use the returned url in your results to add to the array of urls.
    I haven’t found the time to play around with this yet …

    #58128
    Anonymous
    Inactive

    Thanks for already have taken the time to present these bricks. Even if I am not able to deal with them just like that. I guess I will come back to this when I feel more capacity in my mind and am more eager to learn the necessary things. Or maybe someone else has the need and knowledge to realize it in the meantime 😉

    #58148
    Franky
    Keymaster

    This seems to do the trick (add to your theme’s function.php):

    
    add_filter('wp_link_query', 'eme_add_events_link_search', 10, 2);
    add_filter('wp_link_query', 'eme_add_locations_link_search', 10, 3);
    function eme_add_events_link_search($results,$query) {
        if (!isset($query['s'])) return;
        if ( $query['offset'] > 0 ) : // Add only on the first result page
            return $results;
        endif;
        $events=eme_search_events($query['s']);
        foreach ($events as $event) {
             $results[]= array(
                        'ID' => $event['event_id'],
                        'title' => trim( esc_html( strip_tags($event['event_name']) ) ) ,
                        'permalink' => eme_event_url($event),
                        'info' => 'Event',
                    );
        }
        return $results;
    }
    function eme_add_locations_link_search($results,$query) {
        if (!isset($query['s'])) return;
        if ( $query['offset'] > 0 ) : // Add only on the first result page
            return $results;
        endif;
        $locations=eme_search_locations($query['s']);
        foreach ($locations as $location) {
             $results[]= array(
                        'ID' => $location['location_id'],
                        'title' => trim( esc_html( strip_tags($location['location_name']) ) ) ,
                        'permalink' => eme_location_url($location),
                        'info' => 'Location',
                    );
        }
        return $results;
    }
    
    #58149
    Anonymous
    Inactive

    Amazing! Thanks a lot for that working piece of extra code. It seems to do what I wanted. I am not sure yet if I welcome the fact that all entries of an recurring event are listed. Would it be easy to adjust the code for only showing single events?

    By checking this function I discovered that the code I linked above (to find categories and tags) isn’t working properly. The results are repeated all over again and again. The most obvious thing to do is to contact the author, sure. But maybe you have taken a look at it or even used it to approach your solution and perhaps seen something that my cause this? I am aware that it is far out of your business, just wondering.

    #58152
    Franky
    Keymaster

    The next version of EME will have an option that allows to activate/deactivate the link search for events/locations. I also added the date for events, so you can better distinguish events in a recurrent series (I will not remove those from the search though since that would defeat the purpose of it all).

    #58156
    Anonymous
    Inactive

    Veeeery good. Thank you a lot.

    #58157
    Franky
    Keymaster

    Concerning your question about the github code: it seems the second function (for linking terms) doesn’t contain the following 3 lines (like the first function):

    
        if ( $query['offset'] > 0 ) : // Add only on the first result page
            return $results;
        endif;
    

    I’m guessing that’s causing the results to be repeated …

    #58158
    Anonymous
    Inactive

    You guessed right. Very kind of you to help me also with that.

Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘How do I …’ is closed to new topics and replies.
Scroll to Top