Home › Forums › Calendar Products › Events Calendar PRO › Specify near location field from stored data
- This topic has 4 replies, 3 voices, and was last updated 10 years, 1 month ago by
Support Droid.
-
AuthorPosts
-
March 29, 2016 at 4:16 am #1095302
Lee
ParticipantI have a website in local development which users can select their local area and then content is targeted at their location. On the events calendar page I was hoping to automatically fill in the near location field for them, so that it shows local events. Any ideas on how this can be done?
Also I was wondering if you can specify location on the widget as well?
Thanks.
March 29, 2016 at 5:11 am #1095312Brook
ParticipantHowdy Lee!
I would love to help you with this.
We actually have added a feature request for this. Please be sure to vote on it if this is something you’d like to see us build.
This is certainly possible to build now as a customization though, if you’re so inclined. First you should setup a PHP script on your site, perhaps call it events-near-me.php. Now when a user hits this page you should geocode their IP address using whatever geocoding service you prefer. Now that you have a long/lat and location name for the user you should HTTP redirect them to the maps page (example.com/events/map/. But fill in three query variables for them:
example.com/events/map/?tribe-bar-geoloc-lat=[INSERT LATITURE HERE]&tribe-bar-geoloc-lng=[INSERT LATITURE HERE]&tribe-bar-geoloc=[INSERT NAME OF LOCATION/CITY HERE]And there you go! Now you can link to this page, and it will automatically return events near the user.
You can do something similar a widget if you’re so inclined, but it will be a lot more involved. You will need to alter the WP Query for the widget to include the location of the user. This would be a pretty advanced PHP script compared to the above.
Does that all make sense? Will that work for you? Please let me know.
Cheers!
– Brook
March 30, 2016 at 9:34 am #1095939Lee
ParticipantThanks Brook.
I looked into the query variables closer and found out that there is a hook called ‘tribe-events-bar-filters’ that I can call which allows me to specify these from the stored data I have, if they are not set in the web address from submitting a new location. This seems to be working a treat. I have put the code below if you want to have a look. Thanks!
function set_events_location() { if (empty($_REQUEST['tribe-bar-geoloc-lat']) && empty($_REQUEST['tribe-bar-geoloc-lng']) && empty($_REQUEST['tribe-bar-geoloc'])) { $_REQUEST['tribe-bar-geoloc-lat'] = '__LATITUDE_HERE__'; $_REQUEST['tribe-bar-geoloc-lng'] = '__LONGITUDE_HERE__' $_REQUEST['tribe-bar-geoloc'] = '__PLACE_NAME_HERE__'; } } add_filter('tribe-events-bar-filters', 'set_events_location', 0, 0);-
This reply was modified 10 years, 1 month ago by
Lee.
March 31, 2016 at 1:03 am #1096261Brook
ParticipantThat’s excellent Lee. Nice clean code.
The only reason I suggested making a separate file/URL was so you could still show all events if you wanted. If you are prefilling the search on the home page, then I believe it will prevent the user from being able view events from all locations at once. Depending on your site this may or may not be something you desire. And I have not yet tested your code, so perhaps you found a way to work around that which I’m not seeing.
Thanks for getting back! Let me know if you need anything else. Cheers!
- Brook
April 15, 2016 at 9:35 am #1103056Support Droid
KeymasterThis topic has not been active for quite some time and will now be closed.
If you still need assistance please simply open a new topic (linking to this one if necessary)
and one of the team will be only too happy to help. -
This reply was modified 10 years, 1 month ago by
-
AuthorPosts
- The topic ‘Specify near location field from stored data’ is closed to new replies.
