This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Pass Dynamic Value To Custom Redirect URL

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Pass Dynamic Value To Custom Redirect URL

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #46345
    pointydrippointydrip
    Participant

    I saw there is a similar request made last month but it is marked private.

    I have ‘live’ search results from “search instance 1” (my ‘clean and lean’ search) but if the user hits enter or search icon I want it to redirect to another search page where the values are passed along to “search instance 2” which has more detailed search options, but the previous values have already been kept.

    Are there any examples of this?

    (the Frontend filters API was incredibly helpful btw)

    #46351
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    This may not be possible this way I’m afraid. The data is not shared on purpose, because each instance can have different filter setups and the initial values depend on both the query arguments as well as on the configuration. Different configurations require different data sent through the query arguments depending on the filter types.

    Nevertheless, the ‘p_asid’ query argument determines which search ID the query arguments are referring to. With this code you can hook into that:

    add_action('wp_footer', 'asp_custom_footer_script', 99999);
    function asp_custom_footer_script() {
    	?>
    	<script>
    	document.addEventListener("DOMContentLoaded", (event) => {
    		WPD.Hooks.addFilter('asp_redirect_url', function(url){
    			return url.replace(
    				"p_asid=1", 
    				"p_asid=2"
    			);
    		}, 10);
    	});
    	</script>
    	<?php
    }

    This changes the redirection from search ID=1 to search ID=2 so all the query arguments are passed on. However this does not guarantee that they will work unfortunately.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.