Skip Navigation

[Resolved] Query Filter in custom search

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to hide the results of a View until someone selects a filter.

Solution: Use the following 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 );
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.

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 1 reply, has 1 voice.

Last updated by Rostislav Avtodiychuk 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1327437

Tell us what you are trying to do? I created a custom search for holiday hidden link

Is there any documentation that you are following?

Is there a similar example that we can see?
By default, my page shows all holidays from January. Can I show on my page by default all holidays in the current month?
But if user want to search on-page search by the current year.

As alternate not show any on-page, only searching forms and after use filter show results on page in my loop.

What is the link to your site?
hidden link

Thank you

#1334319

Hello, Christian, I'm sorry for my delay, I don't see youк answer from support in my email 🙁
I'll try your function and it worked perfectly! Thank you very much!
My issue is resolved now. Thank you!