Automatically apply a map filter using a URL or Query String

Home Forums MapPress Support Automatically apply a map filter using a URL or Query String

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #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 UI

    My 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.

    #21020
    Chris
    Keymaster

      Hi,

      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.

      #21021

      Thanks 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 well

      What 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 filter

      This is where I am at:

      I am using a URL /map/?location_type=cafe-shop

      my 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

    Viewing 3 posts - 1 through 3 (of 3 total)
    • You must be logged in to reply to this topic.