Home › Forums › MapPress Support › Automatically apply a map filter using a URL or Query String
Tagged: filters, query string
- This topic has 1 reply, 1 voice, and was last updated 2 years ago by
Chris.
-
AuthorPosts
-
August 11, 2024 at 10:47 pm #21018
Hi,
Does anyone know if it is possible to apply a filter to a map using the page URL.
For example,
I have a map with multiple POIs with different categories e.g. cat_1, cat_2, cat_3
It has filters set up using the categories: cat_1, cat_2, cat_3
Pins can be filtered using the build in Filters in the UIMy question is can I apply a filter automatically using the URL. e.g. http://www.mywebsite/map?filter=cat_3
I can then link to the map and have a filter applied automatically.I expect I can do something like this using https://developer.wordpress.org/reference/functions/get_query_var/ and call a filter function on the map.
Has anyone done anything like this?
Any help much appreciated.
August 11, 2024 at 10:50 pm #21020Hi,
You should be able to do this for mashups using the [mashup] shortcode. There are some examples in the plugin documentation. You can use variables in the mashup query to indicate WordPress query variables, such as categories.
October 6, 2024 at 12:33 pm #21021Thanks for your help.
I have tried that and it works for a single filter. But once I have done that I can’t use the filters on the map on the front end.
To give you more context…
My setup:
– I have a Mashup map displaying all ‘location’ posts (custom posts)
– I have a ‘location_type’ custom taxonomy set on ‘location’ posts
– My map has a filter setup in the MapPress plugin settings using location_types as check boxes
– I can filter the locations posts using the map filter UI on the location_types – this is all working really wellWhat I’d like to do is:
– apply a filter to the map from the URL
– see the filter appplied to the map on the filter UI
– change the map filter using the filter UI to a different filterThis is where I am at:
I am using a URL
/map/?location_type=cafe-shopmy PHP is
if ( get_query_var('location_type') ) { $filter = get_query_var('location_type'); echo do_shortcode('[mashup query="post_type=location&location_type=' . $filter. '"]'); }The map filters by ‘cafe-shop’ as expected.
Issues:
– The filter list on the UI does not have ‘cafe-shop’ selected
– If I try to change the filter to something else usising the UI, the filter does not work, it stays on ‘cafe-shop’Is there a way of pre-filtering the map and then allowing the user to interact with the filters?
Thanks
-
AuthorPosts
- You must be logged in to reply to this topic.
