The Grid: link to open filter on url

Hello,

I am using “The Grid” plugin to display a list of custom posts that are able to be filtered by category. I was wondering if there was a way for me to link to this page in a way that will trigger the specific filter on page load, depending on the parameter that I can pass through the url (ex. resources/#pdf - will select the PDF category filter, resources/#video - will select the Video category filter, etc…). I know I am able to do this with tabbed areas and accordion items, using some javascript. Does anyone know if there is a similar solution for selection filters within The Grid plugin?

Thanks,

So I figured out the solution to my problem, if anyone is interested here was my solution:

  if(window.location.hash) { //detect hash in the url
    var hash = window.location.hash.substring(1); //strip the hash
    if (hash == "tab-1") { //check for hash "tab-1"
     setTimeout(function() { //delay trigger for 1 second after page load
      jQuery("[data-filter*='.f5']").trigger("click"); //simulate click on element with the data-filter value related to hash "tab-1"
     }, 1000);
    }
    if (hash == "tab-2") { //check for hash "tab-2"
     setTimeout(function() { //delay trigger for 1 second after page load
      jQuery("[data-filter*='.f6']").trigger("click"); //simulate click on element with the data-filter value related to hash "tab-2"
     }, 1000);
    }
    if (hash == "tab-3") { //check for hash "tab-3"
     setTimeout(function() { //delay trigger for 1 second after page load
      jQuery("[data-filter*='.f7']").trigger("click"); //simulate click on element with the data-filter value related to hash "tab-3"
     }, 1000);
    }
  } else {
    // No hash found so do nothing
  }

The data-filters and hash values may be different for you but this is the main javascript that I used in javascript portion of “The Grid” settings.

Hope this helps someone.

Hi @michigancreative,

Thanks for sharing! That’s going to be helpful, I also tried it but there’s a bit of glitch. Maybe it depends on a setup, will add on my list :slight_smile:

Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.