Forums › Forums › Search & Filter Pro › Trigger search submit
Tagged: post type query, Submit, trigger search
- This topic has 4 replies, 2 voices, and was last updated 5 years, 4 months ago by Trevor.
-
Anonymous(Private) June 10, 2019 at 7:57 pm #213745
Hi,
Is there a way to trigger the search form to submit aside from clicking the actual submit button?
I currently have functionality on my search results page, that if it finds matches for a particular post type, it’ll give the user a suggestion like, “We’ve found events related to your search term – click here to view results.”
I want the search form to re-submit/update the query – which is really the equivalent of manually using the post type filter dropdown and setting it to that post type if they used the submit button. But I want to trigger the same thing from a different button outside the form. Is that possible? Or do I have to hook into that form and add my custom button/text suggestion?
Thanks!
Anonymous(Private) June 11, 2019 at 8:21 pm #213838Actually I figured out a way. Since I’m working in WordPress, most of what I need is in the query vars. So I manually re-created the url that the form generates when it filters by post type, and just ensured that I was pulling the shortcode ID, the search term that is encoded dynamically so that it wasn’t hardcoded.
Worked like a charm without having to worry about hooks or JS or anything fancy. I added a setting on the admin so that I could add the ID of the shortcode and have it dynamically pull into the template on the shortcode call without having to hardcode that either. So it’s there as a fall back in case the shortcode ID isn’t present in the query vars.
Here is an example of what the code looks like, in case it helps someone:
$search_term = get_search_query(); $get_shortcode_id = Search_Helpers::get_sf_pro_shortcode_id(); $shortcode_id_query = isset( $wp_query->query_vars['sfid'] ) && ! empty( $wp_query->query_vars['sfid'] ) ? $wp_query->query_vars['sfid'] : $get_shortcode_id; $raw_search_term = rawurlencode( $search_term ); <div class="alert alert-info event"> <p>We've found upcoming events related to your search term "<?php echo $search_term; ?>". <a href="<?php echo home_url() . '/?sfid=' . $shortcode_id_query . '&_sf_s=' . $raw_search_term . '&post_types=event'; ?>"> Go to related events <span aria-hidden="true" class="glyphicon-chevron-right glyphicon"></span> </a> </p> </div>
-
AuthorPosts