Skip Navigation

[Resolved] Show empty result before searching is initiated. Blocks view

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 jose-luisD-2 1 year, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2609895
Captura de pantalla 2023-05-24 152328.png

Tell us what you are trying to do?
Hello, I'm creating a custom search view in blocks in my page. I have worked with views with the legacy plugin, but in this case I'm using Blocks. I need to generate the code or the setting to show empty results in the view output until I insert the searching criteria in the custom search fields.
Is there any documentation that you are following?
I found information about code snippet but it doesn't work.
Is there a similar example that we can see?

What is the link to your site?
hidden link

#2610027

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

The link you shared I do not see the view as it seems I might require login to access that page.

However, if you do not want to display any results under until the search is performed, you will require to use the view's filter hook: wpv_filter_query

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

add_filter( 'wpv_filter_query', 'func_display_no_result_by_default', 10, 3 );
     function func_display_no_result_by_default( $query_args, $setting,$view_id ) {
    if($view_id == 99999) {
 
         if(!isset($_REQUEST['wpv_filter_submit'])) {
            $query_args['post__in'] = array(0);
        }
    }
    return $query_args;
}

Where:
- Please replace 99999 with your original view ID
- please adjust the filter code if required as per your requirement

More info:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#2610129

Hello Minesh
Thanks a lot for your response. Normally with views, the ID was in the views log. But in this case (in block) there is no an ID and there is no log. I put a number in an ID field in the edition menu but it didn’t work. How can I do in this case??

#2610131

Minesh
Supporter

Languages: English (English )

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

To check or know the view number/ID you can enable the legacy version of the views and then navigate to Toolset => Views and then locate your view and you will see the ID there.

More info:
- https://toolset.com/course-lesson/enabling-legacy-version-of-toolset-views/

#2610541

My issue is resolved now. Thank you!