Linking to filter on Post Grid

Q&ACategory: PluginLinking to filter on Post Grid
iwantthem asked 1 year ago

Hi there,
Is it possible to link to a specific filter on Post Grid?
I notice the URL doesn’t change when clicking a filter in page. Can I add a parameter to the URL to do this? http://mysite.com/my-page-with-grid.php=filter-name
OR is it possible to use something like jQuery to activate the filter if it knew where you came from? e.g. clicking a specific DIV with a class like .filter1.
I hope this makes sense.
 
Many thanks
 
Steve

4 Answers
Best Answer
iwantthem answered 1 year ago

I managed to get this working. I enqueued a small JS script only on my Post Grid page (code below).

jQuery(document).ready(function($){

//Get URL and strip it down
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

//Get the filter varible
var filter = getParameterByName('filter');

//If there is something in filter action the click and add active class
if(filter){
setTimeout(function() {
$('div[data-filter=".'+filter+'"]').trigger('click').addClass( "active" );
},10);
};


});

Going to http://mysite.com/post-grid-page/?filter=climbing loads the post grid page and once loaded ‘clicks’ the climbing filter.
Just thought I’d post it here in case anyone else wanted to do it.
Cheers,
S

Hasan Staff answered 1 year ago

Welcome to our forum,
Probably answer is No, Post Grid is generated by shortcode all parameter come from post meta,
 
Can you please give me a live example what you like to do ?
 
Regards

iwantthem answered 1 year ago

Hello,
Thanks for your reply.

Here’s a site that does what I mean. I know it’s not running wordpress, but you can see that when you click a filter, it adds a parameter to the URL allowing you to link directly to that page with the filter active.

Grid:
http://www.theclymb.com/adventures

Grid with climbing adventure selected:
http://www.theclymb.com/adventures?activities=Climb
 
I was wondering if it would be possible to use jQuery (or something) to trigger the click event on the appropriate filter when the page loads. That is, if I’ve come from a specific HTML element (or class name) on another page.

e.g. Lets say I have 4 images on my homepage that show the names of my filters on them (climbing, trekking, biking, rafting). A Post Grid with filters is on another page. When I click on the ‘Climbing’ image on the homepage, I’d like to go to the Post Grid page with the ‘Climbing’ filter selected.

I hope that helps.

Thanks again for your time.

Steve
 

Hasan Staff replied 1 year ago

Thanks for your explain & demo link, this is advance filtering , its seems our plugin can’t play this role, although we have filterable(Basic) grid by terms/categories,here is the demo http://paratheme.com/demo/post-grid/?demo=filterable-grid

iwantthem answered 1 year ago

No problem.
I am currently using your Post Grid plugin and have the filters working. I just wanted to load the page with a filter active.
Ok, so there is no way to load your link with “Albums” active?
Hmmmm, I’m wondering if there is a way to hack it some how…