Forums Forums Search & Filter Pro How to add a string to end of every Search Results URL

Viewing 9 posts - 11 through 19 (of 19 total)
  • Anonymous
    #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

    Trevor
    #209430
    This reply has been marked as private.
    Anonymous
    #209434

    Ok, waiting:)

    Anonymous
    #209442

    I 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?

    Anonymous
    #209495

    I have absolutely same problem! URL duplicated

    Ross Moderator
    #209869

    Hi 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
    #210193

    It 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
    #210437

    Hi 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

    Anonymous
    #210889

    Thanks!

Viewing 9 posts - 11 through 19 (of 19 total)