Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Clicking on a suggested search keyword
- This topic has 5 replies, 2 voices, and was last updated 2 years, 8 months ago by
Ernest Marcinko.
-
AuthorPosts
-
September 15, 2023 at 11:43 am #45393
Adam Sarkadi
ParticipantHello!
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.
September 15, 2023 at 4:24 pm #45399Ernest Marcinko
KeymasterHi,
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 }September 18, 2023 at 10:48 am #45408Adam Sarkadi
ParticipantHello,
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 thesearchRedirectmethod 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,
AdamSeptember 18, 2023 at 1:58 pm #45413Ernest Marcinko
KeymasterSure, 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 }September 18, 2023 at 2:17 pm #45418Adam Sarkadi
ParticipantThat does the job!
Thank you for your help! I think this ticket can be closed.
September 18, 2023 at 2:25 pm #45421Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- The topic ‘Clicking on a suggested search keyword’ is closed to new replies.