WordPress.org

Forums

Events Manager
[resolved] Dedicated Locations Search (14 posts)

  1. adzay
    Member
    Posted 2 years ago #

    I have been trying to make a Locations search similar to events search. Can you help me out?

    I copied events-search and then renamed it to location search.
    I modified the locations-list file to make it more similar to Events list.

    You can find the monstrosity I came up with at the following link: https://gist.github.com/adzay/717a41afa2e32dc0394e

    I replaced ‘EM_Events::’ with ‘EM_Locations::’ Hoping it would make the search for locations. But it did not work.

    I also saw the following in my location- search file. ‘<input type="hidden" name="action" value="search_events" />’

    I changed “search_events” into “search_locations”. And I did this in the locations-list php file aswell.

    In the file the following section works because it calls my locations-search.php on top of my locations list.

    if( get_option('dbem_events_page_search') && !defined('DOING_AJAX') ){
      em_locate_template('templates/locations-search.php',true);
    }

    But when I actually press search it gives me the default Events table instead of results in the locations list format I just sent you.

    I found this on line 544 of em-actions in the main plugin directory.

    }elseif( $_REQUEST['action'] == 'search_events' && get_option('dbem_events_page_search') && defined('DOING_AJAX') ){
    			$args = EM_Events::get_post_search();
    			if( empty($args['scope']) ){
    			    $args['scope'] = get_option('dbem_events_page_scope');
    			}
    			$args['owner'] = false;
    			ob_start();
    			em_locate_template('templates/events-list.php', true, array('args'=>$args)); //if successful, this template overrides the settings and defaults, including search
    			echo apply_filters('em_ajax_search_events', ob_get_clean(), $args);
    			exit();
    		}

    I duplicated that and made it for locations:

    elseif( $_REQUEST['action'] == 'search_locations' && get_option('dbem_events_page_search') && defined('DOING_AJAX') ){
    			$args2 = EM_Locations::get_post_search();
    			if( empty($args['scope']) ){
    			    $args['scope'] = get_option('dbem_events_page_scope');
    			}
    			$args['owner'] = false;
    			ob_start();
    			em_locate_template('templates/locations-list.php', true, array('args'=>$args)); //if successful, this template overrides the settings and defaults, including search
    			echo apply_filters('em_ajax_search_events', ob_get_clean(), $args);
    			exit();
    		}

    Doing this gives me an error because it is unable to define EM_Locations::get_post_search();.
    Can you guys help me with this please?

    http://wordpress.org/extend/plugins/events-manager/

  2. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    sorry, big backlog over the holidays so can't help atm...

    however, the latest update should already search locations too. there's also the shortcode/PHP attribute 'search' which should work for locations too if that helps

  3. adzay
    Member
    Posted 2 years ago #

    Hi Marcus,

    How do I activate the locations search feature?

  4. agelonwl
    Member
    Posted 2 years ago #

    hi,

    you can use search attribute 'search' on shortcode [locations_list search="test location"] or using template file templates/templates/locations-list.php like $args['pagination'] = 'test location';

    http://wp-events-plugin.com/documentation/event-search-attributes/

  5. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    locations are automatically searched in the text box for event searches on the default search form.

  6. Daedalon
    Member
    Posted 2 years ago #

    What's missing is a search that returns locations, not events. The exact equivalent of the same that already exists for events but so that it wouldn't have to be aware of anything else than locations.

    For me it's odd that this form isn't sitting in the top of the locations list by default, since this would be very useful and I'd imagine adding the feature in core wouldn't take many hours by reusing the code of event search.

  7. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    we're working on some search alternatives for locations (which will also optionally include geocoding)

    that said, creating a form/search function isn't terribly hard already, e.g. you can feed the search string like this:

    echo EM_Locations::output(array('search'=>$search));

  8. adzay
    Member
    Posted 2 years ago #

    Hi Daedsalon, what you are saying is right, but I am just gratefull the plugin has all the features it currently has, so Im going to be patient.

    Below is what i used for my dedicated locations search page

    <?php
    $counties = $_GET['country'];
    $region = $_GET['region'];
    $town = $_GET['town'];
    $state = $_GET['state'];
    $search = $_GET['em_search'];
    
    $args['page'] = (!empty($_REQUEST['pno']) && is_numeric($_REQUEST['pno']) )? $_REQUEST['pno'] : 1;
    $args['offset'] = ($args['page']-1)*$args['limit'];
    $args['pagination'] = true;
    $args['scope'] = 'future';
    $args['country'] = $counties;
    $args['state'] = $state;
    $args['town'] = $town;
    $args['region'] = $region;
    $args['search'] = $search;
    
    	$args['format'] = '<div> your format </div>

    and then echo EM_Locations::output(apply_filters('em_content_locations_args', $args));

  9. adzay
    Member
    Posted 2 years ago #

    Btw Marcus, as you are currently making a search form with add geozipping. Can your team please be active on the following thread

    http://wordpress.org/support/topic/plugin-events-manager-add-simple-placeholder-for-zip-code-distance?

    It will be really helpful.

  10. Daedalon
    Member
    Posted 2 years ago #

    Thanks a ton, Adzay. Based on your code I made a complete 2-step copy-paste patch to add location search to Events Manager. I mixed several typos and other errors, added JavaScript to make the search form not send the default value and removed unnecessary code, such as events-only code (scope, categories), and combined the variable operations from the above patch (eg. $args['search'] = $_GET['em_search'];).

    Hopefully this one gets added into core soon. I have been surprised that this feature hasn't been in core since the early days of the plugin, so it's a great time to add it there. If this wasn't so easy to do in the end I'd say it's time to increase the version number to 5.4 :)

  11. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    @adzay, just answered it a few mins ago ;)

    as you can see, it's not so straightforward as it seemed, but we have some cool ideas to get this working.

  12. adzay
    Member
    Posted 2 years ago #

    @Daedalon , Glad to see my minimal php knowledge helped someone out. :)

    Funny enough, i worked that out but I just cant figure out a way to have one universal search form with a check box to choose whether it is a "event search" or "Location search" to decide whether to redirect the user to Locations List or Events list... If I find it I will also post.

  13. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    will take that into consideration when making our one.

  14. Daedalon
    Member
    Posted 2 years ago #

    Adzay, that's rather simple. Can't give a proper example right now, but the way to do it would be roughly:

    1. Add a new field to the form, perhaps a dropdown or a radio button (checkbox only if you want user to be able to check both; or to have one option only, eg. "search for locations, not events")

    2. Check for that value in PHP, and based on that, go for either EM_Events or EM_Locations::output(apply_filters('em_content_locations_args', $args));

    I myself have been considering having the main search form search for both at the same time, and it would display both. The main question now is the UI, what to display. Eg. up to 5 locations first, then up to 20 upcoming events? Luckily EM will handle the paging, but not the UI decisions :)

    Having a universal Events OR Locations search form on EM front page might be good, though. I'll keep this in consideration. If we decide to try this, I'll create one and share the code.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic