automatic searching via link

Home Forums Product Support Forums Ajax Search Pro for WordPress Support automatic searching via link

This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 6 years, 5 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #7871
    Ralf Heijkants
    Ralf Heijkants
    Participant

    Dear Wp-dreams,

    I would like to make a link to the search tool: If one clicks on a word/link (possibly on other pages) it automatically starts a search based on the word (or whatever the link points to).

    Is this possible?

    Another theoretical example: if one would click on the word ‘possible’ in the line above one would automatically start searching using the word ‘possible’.

    Regards,
    Ralf

    #7873
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    Well, that’s not possible unless with some extra code. I’ve taken some time to experiment and came up with a possible solution.

    This solution will basically target a specific group of links and perform a search based on the link text and scroll the screen to the search bar to be visible.

    1. Custom Javascript code. Put this code to the footer of your theme footer.php file, just before the closing body tag:

    <script>
    jQuery(function($) {
      $('a.do_search').click(function(e){
        e.preventDefault();
        $('input.orig').val(jQuery(this).html());
        setTimeout(function(){
          $('input.orig').keyup();
        }, 300);
        $('body, html').animate({
            "scrollTop": $('input.orig').offset().top - 100
        }, {
            duration: 500
        });
      });
    });
    </script>

    2. For links you want to trigger a search, add this class: “do_search”, like so: https://i.imgur.com/FrEw7QN.png

    If the user clicks on this link a search will be performed and the screen scrolled to the search location.

    Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.