Skip Navigation

[Resolved] The search function for zip codes and categories won't submit correctly

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 4.22 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Christian Cox 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1323667

I am trying to:
I was able to get the custom search function added to the page. However, it seems as though the submit button and reset button are not functional.

I'm also wondering how I can hide the search results from appearing on the page prior to a search being conducted. Currently they display as an unordered list beneath the search bar.

My goal is to have a custom search that will allow a user to enter in the zip code as text and select a home service category which after submitting will output a partner page (custom post type).

hidden link to a page where the issue can be seen:

I expected to see: one searchable type field for zip codes, one category dropdown that I could submit to find a custom post type associated with the zip code and category.

Instead, I got: the posts displaying before I've submitted, the text search field not pulling the zip code and submit and reset buttons not working.

#1323725

I was able to get the search function working like I want it to. However, before I submit anything, the current posts are listed below the search fields (blind and shutter spot, test hoa partner). You can see what I mean here hidden link . How can I get these to go away? And if I want to display my results on another page, how would I do that?

#1323889

How can I get these to go away?
Hello, if you want to hide the search results until some query filter is submitted, you can add the following custom code to your child theme's functions.php file or create a custom code snippet in Toolset > Settings > Custom Code:

/**
 * No initial results
 *
 * Don't show View results until a filter has been applied
 * 
 * Tests for custom field filters, taxonomy filters, or text searches
 */
function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){
  
	$target_views = array( 12345 ); // Edit to add IDs of Views to add this to

    if ( in_array( $view_id, $target_views ) ) {
  
        // if there is a search term set
        if ( !isset( $query_results->query['meta_query'] ) && !isset( $query_results->query['tax_query'] ) && !isset( $query_results->query['s'] ) ) {
            $query_results->posts = array();
            $query_results->post_count = 0;
            $query_results->found_posts = 0;
        }
    }
  
    return $query_results;
}
add_filter( 'wpv_filter_query_post_process', 'tssupp_no_initial_results', 10, 3 );

Be sure to change 12345 to match the numeric ID of this View.

And if I want to display my results on another page, how would I do that?
First you should create the page where you want to display the results. Insert the View in the Page and choose to display only the results, or both the filters and results, depending on what you want to display here. If you're using the Block Editor, these options will appear in the right column of the editor area. Then, return to the Page where you want to display the filters only. Insert the View and choose to display only the filters. The system will prompt you to decide where to display the results, and you should choose the Page you just created. Again, if you're using the Block Editor, these options will appear in the right column.