- This topic has 22 replies, 4 voices, and was last updated 3 years, 10 months ago by Tom.
-
AuthorPosts
-
June 6, 2020 at 9:54 am #1317072Sam
Hi, I was wondering if there is a way to use the SearchWP Live Ajax Search plugin with the navigation search? It seems to work fine on a regular search form but nothing seems to happen when the search is done from the primary or mobile navigation.
Any help appreciated.
June 6, 2020 at 4:29 pm #1317332LeoStaffCustomer SupportHi there,
Is this what you are looking for?
https://generatepress.com/forums/topic/searchwp-live-search/June 7, 2020 at 4:23 am #1317759SamHi Leo, I did read that and used the snippet provided by Tom, but it did not seem to do anything? The post is from 2017 so I kind of assumed it is probably out of date?
thanks
SamJune 7, 2020 at 7:20 am #1317890DavidStaffCustomer SupportHi there,
can you enable the SearchWP Live Ajax Search plugin.
And add the code Tom provided. Then let us know so we can take a look at why its not working.June 7, 2020 at 7:50 am #1318046SamSure, it is done. Please let me know what you find.
June 7, 2020 at 8:00 am #1318058DavidStaffCustomer SupportI cannot see the changes that function should make.
Have you added any other filter functions for changing its behaviour such as these:https://docs.generatepress.com/article/generate_navigation_search_output/#woocommerce-products
If so can you remove them and then let us know.
June 7, 2020 at 8:08 am #1318072SamAh yes, there is another snippet (see below) which fixes the issue of Woo results being returned as regular post results. Is there a way to combine the two snippets?
Also with the autofill results you have to click on them twice to go to the page, that seems strange, can you advise on why that would be?
add_filter( 'generate_navigation_search_output', 'tu_remove_search_query' ); function tu_remove_search_query() { printf( // WPCS: XSS ok, sanitization ok. '<form method="get" class="search-form navigation-search" action="%1$s"> <input type="search" class="search-field" value="" name="s" title="%2$s" /> <input type="hidden" name="post_type" value="product" /> </form>', esc_url( home_url( '/' ) ), esc_attr_x( 'Search', 'label', 'generatepress' ) ); }
June 7, 2020 at 8:11 am #1318074SamNB
It also fixes the issue of clearing the search field, if you do a search and then a second search from the results page.
June 7, 2020 at 8:24 am #1318083SamOK I think I got it, I added data-swplive=”true” to the input form.
So now the original fix would be:
add_filter( 'generate_navigation_search_output', 'tu_remove_search_query' ); function tu_remove_search_query() { printf( // WPCS: XSS ok, sanitization ok. '<form method="get" class="search-form navigation-search" action="%1$s"> <input type="search" class="search-field" value="" name="s" title="%2$s" data-swplive="true" /> <input type="hidden" name="post_type" value="product" /> </form>', esc_url( home_url( '/' ) ), esc_attr_x( 'Search', 'label', 'generatepress' ) ); }
Still no idea why you have to click a result twice though… ?
thanks
June 7, 2020 at 10:06 am #1318198TomLead DeveloperLead DeveloperHi there,
That’s because of this issue: https://generatepress.com/forums/topic/live-search-results-links-broken-in-primary-nav/#post-1311543
June 8, 2020 at 1:10 am #1318745SamHi Tom, thanks, I see.
Can you advise where I would add this code that has been suggested?
June 8, 2020 at 1:57 am #1318790SamHi Tom, I think I may have an alternative workaround.
SearchWP offer another extension to their plugin that provides a lightweight modal search box: https://searchwp.com/extensions/modal-form/
So I was thinking, instead of messing with the code, is it possible to change the behaviour of the magnifying glass button in the navbar so it launches this modal? The plugin has the functionality to add it as a menu item, but then it ends up in the slide-out menu on mobile, so I thought if you can change the behaviour of the search button to execute their shortcode or they have a function that can be called using the functions.php… could it would be an easy solution?
What do you think, could that work?
June 8, 2020 at 9:43 am #1319527TomLead DeveloperLead DeveloperHi there,
Do they offer instructions on how to add your own toggle? If so, it should be easy enough to hook it into the navigation/mobile navigation using hooks ๐
June 8, 2020 at 9:46 am #1319536SamHi Tom, they advise how to add a button to launch the modal, is that what you mean?
As a Menu Item: https://searchwp.com/extensions/modal-form/#menu-item
Using a Shortcode: https://searchwp.com/extensions/modal-form/#shortcode
As a Gutenberg Block: https://searchwp.com/extensions/modal-form/#block
Within your template(s) programmatically (code): https://searchwp.com/extensions/modal-form/#code\Can you use any of these methods?
thanks
June 8, 2020 at 4:01 pm #1319931TomLead DeveloperLead DeveloperYou could:
1. Add the menu item, then hide it on mobile.
2. Add a new Hook Element to thegenerate_inside_navigation
hook:<div class="mobile-bar-items"> <?php searchwp_modal_form_trigger(); ?> </div>
Then make sure to “Execute PHP” and set your Display Rules.
Let me know if you need more info ๐
-
AuthorPosts
- You must be logged in to reply to this topic.