Skip Navigation

[Resolved] don't show results until a filter is applied

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by Minesh 8 months ago.

Assisted by: Minesh.

Author
Posts
#2688808

Hi, I don't want results to be displayed in a search view until a filter is applied (on hidden link).
I found this solution but it doesn't work in my case: https://toolset.com/forums/topic/dont-show-any-results-until-filter-is-applied/
I think it's because of the search view filter type. I use taxonomy filter and also a field called "Year" (dropdown Custom Search Filter).

How can I do it? Let me know.

Thanks!

#2688816

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Yes - As you have taxonomy filter added only, I've just modified the code as given under. Can you please try to use the following code and try to resolve your issue:

function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){
    
    $target_views = array( 51); // Comma-separated list of View IDs
  
    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'] )  ) {
            $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 );

You can add the above code to "Custom Code" section offered by Toolset:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

#2688858

Hi Minesh, is not working... what am I doing wrong?

#2688964

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share admin access details and tell me where exactly you added the code I shared and let me review whats going wrong with your setup.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2689004

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now.

I've activated the code snippet at "Custom Code" section and adjusted the code as given under:
- hidden link

function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){
     
    $target_views = array(51); // Comma-separated list of View IDs
   
    if ( in_array( $view_id, $target_views ) and !defined( 'DOING_AJAX')) {
     
      
            $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 );

Can you please confirm it's working as expected.

#2689035

It works! Thanks Minesh!!