• Hi, I work with Toolset Types and Views, I can create a custom search box using Views and recently Viwes integrated with Relevanssi.

    I tried to use also Autocomplete For Relevanssi but it doesn’t work with Views search box.

    The problem is that Views doesn’t use the standard WP <input type=”search” name=”s”> field, it uses <input type=”text” name=”wpv_post_search”>.

    Another problem is that Views uses AJAX so I need a funtion to callback.

    I fixed the problem customizing your plugin code to:

    function wpv_autocomplete() {
    
            if (document.getElementsByName("wpv_post_search").length != 0 ) {
                var searchInputs = document.getElementsByName("wpv_post_search");
    
            } else {
                var searchInputs = document.getElementsByName("s");
            }
    
            for(var i = 0; i < searchInputs.length; i++) {
                var awesomplete = new Awesomplete(searchInputs[i]);
                awesomplete.list = ["<?php echo $iwords_list; ?>"];
                awesomplete.minChars = <?php echo $afr_min_chars; ?>;
                awesomplete.maxItems = <?php echo $afr_max_suggestions; ?>;
            }
    }
    wpv_autocomplete();

    So now it works on wpv_post_search and I can also call the function wpv_autocomplete().

    It would be great if you could integrate your plugin with Views by default in the next release.

    thanks
    Umberto

    • This topic was modified 7 years, 8 months ago by umbaumba.
    • This topic was modified 7 years, 8 months ago by Steven Stern (sterndata). Reason: put code in backticks
Viewing 3 replies - 1 through 3 (of 3 total)
  • nicholasag

    (@nicholasagardy)

    Hey Umberto. Thank you for sharing this code.
    Where do I put it?

    Hi is there any news as to whether this might be done? I also need to integrate with the views search filter in Toolset WP-Types. Thanks

    Thread Starter umbaumba

    (@umbaumba)

    Hi, I did it by customizing Autocomplete plugin. You have to edit autocomplete-for-relevanssi.php file and replace this code with my code:

    var searchInputs = document.getElementsByName("s");
        for(var i = 0; i < searchInputs.length; i++) {
            var awesomplete = new Awesomplete(searchInputs[i]);
            awesomplete.list = ["<?php echo $iwords_list; ?>"];
            awesomplete.minChars = <?php echo $afr_min_chars; ?>;
            awesomplete.maxItems = <?php echo $afr_max_suggestions; ?>;
        }
    • This reply was modified 7 years, 4 months ago by umbaumba.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Integrating Autocomplete For Relevanssi with Toolset WP-Views’ is closed to new replies.