taxonomy settings in custom redirect url

Home Forums Product Support Forums Ajax Search Pro for WordPress Support taxonomy settings in custom redirect url

This topic contains 3 replies, has 2 voices, and was last updated by

 
Keymaster
2 years, 4 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #24014

    Participant

    I have a search input field with taxonomy filters on this page (http://test-adrenalised.pantheonsite.io/experiences/).

    I am trying to configure the search button so on click a new tab will open to a custom woocommerce page with the search phrase and selected filters in the URL params.

    While reading your javascript, in the parseCustomRedirectURL method, I notice your plugin looks for filter fields with names matching ‘name*=aspf[‘. However, the taxonomy term fields begin with ‘termset’, not ‘aspf’.

    Is there a way to apply the price, location and category search settings to the custom url?

    #24026

    Hi,

    Indeed, that function is limited at this time to recognize only the custom field related filters. There is however another way to do this, but it is a bit more complicated.

    There is a filter state URL, and it can be requested via the plugin API.
    For that, you need to open your browser developer console, and enter this API method there:

    ASP.api(1, 'getStateURL')

    Change the number ‘1’ to the search ID you have, in case it is different. This should print out a URL like so: https://i.imgur.com/prUknH6.png
    That is the URL of the current filter states on the current page. If you change the filters on the current page, and execute the above code again, it will print out those states. Visiting that URL will automatically preset the filters to the given state.

    In this case, change the filters as you want them, request the filter stat URL via the API call above, then copy that URL. Then, if you need a different configuration, change the filter, run the code again, and a different URL will be generated.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #24082

    Participant
    You cannot access this content.
    #24087

    Hi,

    Well, the base URL is passed in as an argument, and it’s not possible to change it from outsite scope (ex. custom script). The only way to make this work is to implement the change within the core code.

    As this is a modification, I cannot promise anything, but you could try changing the parseCustomRedirect method within wp-content/plugins/ajax-search-pro/js/nomin/jquery.ajaxsearchpro.js from the original, to this:

            parseCustomRedirectURL: function(url ,phrase) {
                var $this = this;
    
                var u = url.replace(/\{phrase\}/g, asp_nice_phrase(phrase));
                var items = u.match(/\{(.*?)\}/g);
                if ( items !== null ) {
                    $.each(items, function(i, v){
                        v = v.replace(/[{}]/g, '');
                        var node = $('input[type=radio][name*="aspf\[' +  v + '_"]:checked', $this.n.searchsettings);
                        if ( node.length == 0 )
                            node =  $('input[type=text][name*="aspf\[' +  v + '_"]', $this.n.searchsettings);
                        if ( node.length == 0 )
                            node =  $('input[type=hidden][name*="aspf\[' +  v + '_"]', $this.n.searchsettings);
                        if ( node.length == 0 )
                            node =  $('select[name*="aspf\[' +  v + '_"]:not([multiple])', $this.n.searchsettings);
                        if ( node.length == 0 )
                            node =  $('input[type=radio][name*="termset\[' +  v + '_"]:checked', $this.n.searchsettings);
                        if ( node.length == 0 )
                            node =  $('input[type=text][name*="termset\[' +  v + '_"]', $this.n.searchsettings);
                        if ( node.length == 0 )
                            node =  $('input[type=hidden][name*="termset\[' +  v + '_"]', $this.n.searchsettings);
                        if ( node.length == 0 )
                            node =  $('select[name*="termset\[' +  v + '_"]:not([multiple])', $this.n.searchsettings);
                        if ( node.length == 0 )
                            return true; // Continue
    
                        var val = node.val();
                        val = "" + val; // Convert anything to string, okay-ish method
                        u = u.replace('{' + v + '}', val);
                    });
                }
                return u;
            },

    You will have to change the script loading method to the ‘Non minified’ on the compatibility options, so that the changes have effect.

    Then try the variables within the custom redirect URL, like so: https://i.imgur.com/37zQxs5.png
    This only affects the drop-down boxes, the slider is a much more complicated. Let me know if this works at least with the drop down boxes.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.