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

Clicking on a suggested search keyword

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Clicking on a suggested search keyword

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #45393
    Adam SarkadiAdam Sarkadi
    Participant

    Hello!
    My client requests that after clicking on a “suggested phrase” (Autocomplete & Suggestions -> Suggested search keywords), the page should be redirected to the search results page (with that keyword query) instead of opening the autocomplete popup.
    Is this possible to do? I could not find any settings in the admin for this.

    Thank you in advance.

    • This topic was modified 2 years, 8 months ago by Adam Sarkadi.
    #45399
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    While there is no option to do that, it should be doable via a bit of custom code to trigger a redirection.

    Try adding this code via the Code Snippets plugin or to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    add_action('wp_footer', 'asp_add_footer_script', 99999);
    function asp_add_footer_script() {
    	?>
    	<script>
    	jQuery(function($){
    		$('.asp-try a').on('click', function(e){
    			let id = $(this).closest('.asp_w_container').data('id');
    			ASP.api(id, 'hideResults');
    			ASP.api(id, 'searchRedirect', jQuery(this).text());
    		});
    	});
    	</script>
    	<?php
    }
    #45408
    Adam SarkadiAdam Sarkadi
    Participant

    Hello,

    I am currently using woocommerce and want to redirect every search to the Woocommerce search results page.

    I am using these settings: (See image attachment)
    It works as expected when I hit enter or click on the magnifier icon, but the searchRedirect method from that snippet seems to ignore these settings and redirects me to the default wordpress search results page instead.

    Is there any way I can fix this?

    Thanks in advance,
    Adam

    #45413
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Sure, I think it’s still doable.

    Please try this variation instead:

    add_action('wp_footer', 'asp_add_footer_script', 99999);
    function asp_add_footer_script() {
    	?>
    	<script>
    	jQuery(function($){
    		$('.asp-try a').on('click', function(e){
    			$(this).closest('.asp_w_container').find('.promagnifier').trigger('click');
    		});
    	});
    	</script>
    	<?php
    }
    #45418
    Adam SarkadiAdam Sarkadi
    Participant

    That does the job!

    Thank you for your help! I think this ticket can be closed.

    #45421
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Clicking on a suggested search keyword’ is closed to new replies.