Clicking on a suggested search keyword

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

This topic contains 5 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 5 months, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #45393
    Adam Sarkadi
    Adam 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 5 months, 1 week ago by Adam Sarkadi .
    #45399
    Ernest Marcinko
    Ernest 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
    }
    Best,
    Ernest Marcinko

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


    #45408
    Adam Sarkadi
    Adam 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

    Attachments:
    You must be logged in to view attached files.
    #45413
    Ernest Marcinko
    Ernest 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
    }
    Best,
    Ernest Marcinko

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


    #45418
    Adam Sarkadi
    Adam Sarkadi
    Participant

    That does the job!

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

    #45421
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.