Events Made Easy › Forums › Bug fixed or feature request implemented › Filter Location and Events list by Town
Tagged: filter
- This topic has 25 replies, 2 voices, and was last updated 11 years, 7 months ago by Franky.
-
AuthorPosts
-
Wed 2 May 2012 at 12:34 #43799AnonymousInactive
Using the filter forms isn’t going to achieve what I want, so I’ve been hacking around and managed to get a distinct list of towns from the database and number of locations in each town using the following query:
SELECT DISTINCT location_town , COUNT( * ) FROM wp_eme_locations GROUP BY location_town
My function gives out the following:
Un-named (6) Birmingham (1) Brighton (2) London (193)
(I’m also trying to sort the results so that London appears first, but that’s a separate issue altogether!)
What I want to be able to do is click on each town name and go to a page with Locations in that town. Currently I’m setting a variable like this:
echo “$location ($num_events) “;
The URL it links to will sanitise the £_GET value and use that as the filter key.
What I can’t work out is how I can use the API or shortcodes to filter locations in a particular town and for the next step do a similar thing for events.
Could you please point me in the right direction? There’s probably a really easy solution but I’m just not seeing it! 🙁
Thanks
Tom
PS – Just donated again 🙂
Wed 2 May 2012 at 21:47 #49723FrankyKeymastereme_get_events() has a parameter where you can give the location ID, so just the events for that location are returned. Is that what you mean?
Thu 3 May 2012 at 04:18 #49724AnonymousInactiveNo – I know about it’s the Town not the Location name.
I mean something like this:
Using the location_town value in the wp_eme_locations table:
eme_get_events_list(“town=$location_town”);
But in this case I’m actually looking at Locations so I would want an eme_get_events_locations() function but ultimately I want to be able to filter locations AND events by town.
I was wondering if you could do something like:
[events_if tag='#_TOWN' value='London'][events_list][/events_if] but I can’t get it working as I think the conditional tags only work inside of the events_list results?
Also I’d probably want this accessible through the API too.
Perhaps I just need to do a feature request for the town to become a parameter in the [events_list] function?
Thu 3 May 2012 at 21:31 #49725FrankyKeymasterWell, I still don’t quite understand it here. You want a list of events per location “town”, not just per location? For the moment it’s indeed not possible, unless you filter it yourself using the available filters, see http://www.e-dynamics.be/wordpress/?cat=41
Mon 7 May 2012 at 13:51 #49726AnonymousInactiveYes that’s what I want to do.
For example, if someone was visiting a town, but didn’t know the locations or events, they could find events or locations within that town.
Am surprised more people haven’t wanted that also to be honest.
Anyway, can you please point me in the right direction as I can’t get my head around this.
So I need to add the following to my theme functions.php ?
add_filter(’eme_location_filter’,’filter_town’);
function filter_town($location) {
Add my code in here
}
Can you please give me a pointer as to what to do next?
I see that eme_locations.php is giving the following SQL query in Line 521:
$sql = “SELECT * FROM $locations_table WHERE location_name != ” $where ORDER BY location_name”;
Do I just re-define the $sql variable to my own MySQL query?
I’m sorry but this is slightly above my experience level, but I have been getting right into the code and looking…
Thanks in advance…
Mon 7 May 2012 at 20:32 #49727FrankyKeymastereme_location_list_filter is the filter you want I guess, but for starters: just do a print_r() of the variable inside the function, and see the result (it contains all locations in this case).
Then in your function, base yourself on e.g. a $_GET variable to get a location town, and only show locations with the town equal to that.
But this might be something for the feature request list.
Tue 8 May 2012 at 14:09 #49728AnonymousInactiveOk – hopefully you can see this as a useful feature then. Should I post in feature requests?
Any idea how likely it is to happen and if so – any idea of when?
Then I can decide whether to attempt a way to hack it together myself.
Don’t mean to sound cheeky.
Thanks
Tom
Wed 9 May 2012 at 19:59 #49729FrankyKeymasterMoved to feature requests.
Sun 29 Jul 2012 at 10:09 #49730AnonymousInactiveHi Franky,
I found that adding the following query string to the Events Page does what I want for this thread.
?eme_eventAction=filter&eme_town_filter=London
I was worried about SQL Injection but it looks like you’re sanitising all the variables already.
What I can’t get my head around is how to create a pretty URL using the eme_insertMyRewriteRules() function.
I know that my ideas may not suit everyone but I was thinking that the following would be great:
http://www.domain.com/%5Bevents page]/ = ALL EVENTS
http://www.domain.com/%5Bevents page]/[location town]/ = ALL EVENTS IN LOCATION TOWN
Can you give me a pointer in how I should approach this and then I’ll have a play around and send you what I come up with.
Once I get this working I think I should be able to work on the nearby events as well which could be along the lines of:
http://www.domain.com/%5Blocations page]/[id]/[location-slug]/[intval] = ALL VENUES WITHIN [intval] distance of current location
Thanks
Sun 29 Jul 2012 at 18:44 #49731FrankyKeymasterTry playing with the rewrite functions, see
eme_insertMyRewriteRules() and eme_insertMyRewriteQueryVars() in events-manager.php
I’m guessing in eme_insertMyRewriteQueryVars() you should add something like:
array_push($vars, 'event_town');
and in insertMyRewriteRules() a new $newrules line (but I didn’t try out which one yet).
Remember: when playing with rewrite rules, deactivate and reactivate the plugin or it might not work …
Tue 9 Apr 2013 at 11:15 #49732AnonymousInactiveHi Franky,
I never got anywhere with this and see it’s still in feature requests.
Any chance of it being considered any time soon?
Thanks
Tom
Tue 9 Apr 2013 at 12:29 #49733FrankyKeymasterI’ll take a look at it tomorrow 🙂
I took a stab at it: not as simple as just inserting rewrite rules. The thing is: using ?eme_eventAction=filter&eme_town_filter=London, you influence just a shortcode on a regular page. There’s no direct url to show events for a town. This would need extra code, after which a rewrite rule can do what you’d like.
Tue 16 Apr 2013 at 05:50 #49734AnonymousInactiveOk – is this likely to make it into a future release?
Tue 16 Apr 2013 at 08:28 #49735FrankyKeymasterit is likely to make it into “a” future release 🙂
No seriously: I’ll do my best, but I have way too much on my agenda … for sure not this evening, unless my stage play rehearsal goes fine 🙂
Tue 16 Apr 2013 at 18:23 #49736AnonymousInactiveHaha – I wasn’t expecting anything that quickly.
The reason I’m asking is I’m planning to get a mobile app developed in android and iOS so I don’t want to get a developer to work on a hack with direct queries to the eme DB if it’s going to appear in a future release.
Am happy to provide the source code for the app to you once done also
Thanks and good luck with rehearsal 🙂
Wed 24 Apr 2013 at 11:42 #49737FrankyKeymasterOk, I created a new function for the filtering, which seems to work fine. But I’m struggling with the rewrite rules …
Wed 24 Apr 2013 at 12:25 #49738FrankyKeymasterOk, found it. These are the changes:
In events-manager.php, replace the 2 function definitions found below:
// Adding a new rule
function eme_insertMyRewriteRules($rules) {
// using pagename as param to index.php causes rewrite troubles if the page is a subpage of another
// luckily for us we have the page id, and this works ok
$page_id=get_option ( 'eme_events_page' );
$events_prefix=eme_permalink_convert(get_option ( 'eme_permalink_events_prefix'));
$locations_prefix=eme_permalink_convert(get_option ( 'eme_permalink_locations_prefix'));
$newrules = array();
$newrules[$events_prefix.'(d{4})-(d{2})-(d{2})'] = 'index.php?page_id='.$page_id.'&calendar_day=$matches[1]-$matches[2]-$matches[3]';
$newrules[$events_prefix.'(d*)/'] = 'index.php?page_id='.$page_id.'&event_id=$matches[1]';
$newrules[$events_prefix.'p(d*)'] = 'index.php?page_id='.$page_id.'&eme_pmt_id=$matches[1]';
$newrules[$events_prefix.'town/(.*)'] = 'index.php?page_id='.$page_id.'&eme_town=$matches[1]';
$newrules[$locations_prefix.'(d*)/'] = 'index.php?page_id='.$page_id.'&location_id=$matches[1]';
return $newrules + $rules;
}
add_filter('rewrite_rules_array','eme_insertMyRewriteRules');
// Adding the id var so that WP recognizes it
function eme_insertMyRewriteQueryVars($vars) {
array_push($vars, 'event_id');
array_push($vars, 'location_id');
array_push($vars, 'calendar_day');
// a bit cryptic for the booking id
array_push($vars, 'eme_pmt_id');
array_push($vars, 'eme_town');
return $vars;
}And in eme_events.php, at the top of function eme_events_page_content:
if (isset ( $wp_query->query_vars['eme_town'] ) && $wp_query->query_vars['eme_town'] != '') {
$eme_town=eme_sanitize_request($wp_query->query_vars['eme_town']);
$location_ids = join(',',eme_get_town_location_ids($eme_town));
$stored_format = get_option('eme_event_list_item_format');
$event_list_format_header = get_option('eme_event_list_item_format_header' );
$event_list_format_header = ( $event_list_format_header != '' ) ? $event_list_format_header : "<ul class='eme_events_list'>";
$event_list_format_footer = get_option('eme_event_list_item_format_footer' );
$event_list_format_footer = ( $event_list_format_footer != '' ) ? $event_list_format_footer : "</ul>";
$page_body = $event_list_format_header . eme_get_events_list ( get_option('eme_event_list_number_items' ), $scope, "ASC", $stored_format, 0, '','',0,'','',0,$location_ids) . $event_list_format_footer;
return $page_body;
}Then just deactivate/reactivate and you can then do things like:
http://localhost/wordpress/events/town/Galway
The thing is: the rewrite rule I added
$newrules[$events_prefix.'town/(.*)'] = 'index.php?page_id='.$page_id.'&eme_town=$matches[1]';
takes everything after “town/”, since the regex “.*” is greedy. I tried to make it non-greedy, but still no luck there.
Wed 24 Apr 2013 at 12:37 #49739FrankyKeymasterOk, weird. While
$newrules[$events_prefix.'town/(.*?)/'] = 'index.php?page_id='.$page_id.'&eme_town=$matches[1]';
doesn’t work (notice the end slash) http://localhost/wordpress/events/town/Galway/ returns a not found),
$newrules[$events_prefix.'town/(.*?)/test'] = 'index.php?page_id='.$page_id.'&eme_town=$matches[1]';
works ok: http://localhost/wordpress/events/town/Galway/test works
So: if you are going to add rules, put the most restrictive one first, like this:
$newrules[$events_prefix.'town/(.*?)/test'] = 'index.php?page_id='.$page_id.'&eme_town=$matches[1]';
$newrules[$events_prefix.'town/(.*?)'] = 'index.php?page_id='.$page_id.'&eme_town=$matches[1]';and not:
$newrules[$events_prefix.'town/(.*?)'] = 'index.php?page_id='.$page_id.'&eme_town=$matches[1]';
$newrules[$events_prefix.'town/(.*?)/test'] = 'index.php?page_id='.$page_id.'&eme_town=$matches[1]';Thu 25 Apr 2013 at 08:02 #49740AnonymousInactiveOk great – I will try this tonight! 🙂
Thanks very much.
Thu 25 Apr 2013 at 08:03 #49741FrankyKeymasterBtw: it is in the trunk version (except the “test” line of course).
So if you come up with some interesting functions: I’ll be glad to integrate them.
Sat 27 Apr 2013 at 12:01 #49742AnonymousInactiveOK – I’ve tried to implement this and made the changes in the two files and deactivated/activated but it’s re-directing to an article that has the town in the post name.
eg: http://plainandsimple.tv/club-listings/town/dubai/ redirects to: http://plainandsimple.tv/2011/10/06/dubai-city-guide/
Also, I’ve never been sure when you say it’s in the trunk version. Does that mean that if I just re-install the plugin it pulls the latest trunk files from server?
Sat 27 Apr 2013 at 12:16 #49743AnonymousInactiveI’m wondering if this is due to my permalinks settings.
Does EME flush the WP rewrite rules on activation?
http://codex.wordpress.org/Function_Reference/flush_rewrite_rules
Sat 27 Apr 2013 at 23:03 #49744FrankyKeymastertrunk=developm ent version
Yes, eme flushes the rewrite rules when reactivating.
It might be that you need to put that rule before another one, I haven’t tries with an event containing the name of a town …
Sun 28 Apr 2013 at 21:34 #49745FrankyKeymasterbtw: just tried it with an event with a town in the title description: no issue.
Mon 29 Apr 2013 at 05:43 #49746AnonymousInactiveMaybe I’ve not understood correctly…
My main page of events (using [events_list] shortcode is here:
http://plainandsimple.tv/club-listings/
I’m assuming that the following should filter to events only in the town specified in the URL:
http://plainandsimple.tv/club-listings/town/dubai/
It’s not working on my side.
1. Where do you download the dev. version (trunk) from?
2. From your last post, do you mean that the ‘town’ in the event ‘title’ doesn’t mess with the filtering based on your regex? Confused by that one.
Thanks
Mon 29 Apr 2013 at 08:10 #49747FrankyKeymasterTry the dev version here:
http://downloads.wordpress.org/plugin/events-made-easy.zip
And for the second question: yes. I created an event with title “Oracle in Antwerp” and location town “Brussel”, and it did not show up when I entered …/town/Antwerp
However: when no event matches the town, it shows all events. I wanted to fix that yesterday evening, but I forgot 🙂
-
AuthorPosts
- The forum ‘Bug fixed or feature request implemented’ is closed to new topics and replies.