Forums › Forums › Search & Filter Pro › How to add a string to end of every Search Results URL
- This topic has 18 replies, 4 voices, and was last updated 5 years, 6 months ago by Anonymous.
-
Anonymous(Private) April 26, 2019 at 11:38 am #209425
Now url is duplicated, in add_query_arg $url is as a key, which is wrong:
https://developer.wordpress.org/reference/functions/add_query_arg/https://xxx.xxx/place/?https://xxx.xxx/place/=tab#promo&_sfm_kariera_miasto=Pi%C5%82a
Anonymous(Private) April 26, 2019 at 1:40 pm #209442I found this on line 4770, search-filter-build.js
var results_url = process_form.getResultsUrl(self, self.results_url); var query_params = self.getUrlParams(true, ''); results_url = self.addUrlParam(results_url, query_params) + '#promo'; window.location.href = results_url;
I’ve added promo. It works, but on every filter. Is is possible to use only with one ID filter or exclude other filter?
Ross Moderator(Private) May 2, 2019 at 11:02 am #209869Hi all
So the original example from Mariusz was the right way to do it:
function change_sf_results_url( $url, $sfid) { //if search form ID = 225, the do something with this query if($sfid==922) { $url = add_query_arg('tab', '#promo', $url); return $url; } } add_filter( 'sf_results_url', 'change_sf_results_url', 10, 2 );
But as mentioned, this is the base URL, the URL to which our search parameters get appended to, so whatever arguments you have here, will have other args appended after in the URL once a search has been performed.
Can I ask, why does the argument have to be last in the list?
Thanks
Anonymous(Private) May 7, 2019 at 7:50 am #210193It needs to be last because I use S&F in one tab, which is showing when the link is for example http://domain.com/products/product-new#details. Tabs are showing through #tabname
Ross Moderator(Private) May 8, 2019 at 11:47 am #210437Hi Mariusz
I see what you mean 😉
So I figured a solution, as in your case the url hash is only so that it can be shared / bookmarked.
What we do is, when an ajax search is finished, we update the URL hash using Javascript, so we use our own JS event for detecting when an ajax request has finished, and them some vanilla JS to update the URL:
(function ( $ ) { "use strict"; $(function () { $(document).on("sf:ajaxfinish", ".searchandfilter", function(){ window.location.hash = 'something'; }); }); }(jQuery));
I hope that helps 🙂
Best
-
AuthorPosts