Problem: I have a View that uses a post ID filter based on a URL parameter. I am able to use the URL parameter array to show multiple posts in the View results. I would like to be able to allow my Users to click a button next to any result to remove that result from the list, and show an updated list of results. For example, here is the URL format for the View:
@http://mysite.com/?post_ids%5B%5D=24&post_ids%5B%5D=23&post_ids%5B%5D=22&post_ids%5B%5D=21&s=
I would like to be able to click a button next to post ID 23 and end up at a URL like this:
@http://mysite.com/?post_ids%5B%5D=24&post_ids%5B%5D=22&post_ids%5B%5D=21&s=
Solution: I can't think of any easy way to do this without some JavaScript URL manipulation. Something like this:
jQuery('#wpv-supplier-comparison :submit').click(function(e){ e.preventDefault(); var url = window.location.href, val = jQuery(e.target).val(), firstVarString = '?post_ids%5B%5D=' + val, notFirstVarString = '&post_ids%5B%5D=' + val, firstVarPos = url.indexOf(firstVarString), notFirstVarPos = url.indexOf(notFirstVarString), pos = firstVarPos > -1 ? firstVarPos : notFirstVarPos, varString = firstVarPos > -1 ? firstVarString : notFirstVarString, urlArray = url.split(varString, 2), newUrl = urlArray[0] + urlArray[1]; if(newUrl.indexOf('?') < 0) { newUrl = newUrl.substr(0,newUrl.indexOf('&')) + '?' + newUrl.substr(newUrl.indexOf('&')+1); } window.location.href = newUrl; });
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 6 years, 7 months ago.
Assisted by: Christian Cox.