Skip Navigation

[Resolved] hide posts in views 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 8 replies, has 2 voices.

Last updated by Minesh 2 years ago.

Assisted by: Minesh.

Author
Posts
#2628587

Hi
I would like to hide the view results until a user choose filter.
In this view:
hidden link
I am not a technical guy so need simple instructions, or maybe you can do it for me?

REMOVED ACCESS
Thanks
Ron

#2628683

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I've added the following code to "Custom Code" section offered by Toolset with the code snippet name "toolset-custom-code":
=> hidden link

add_filter('wpv_filter_query', 'func_hide_search_result_until_search_perform', 10, 3);
function func_hide_search_result_until_search_perform( $query_args, $view_settings, $view_id ) {
     
    if($view_id == 60685 ){
         if( !isset($_REQUEST['wpv_view_count']))  {
            $query_args['post__in'] = array(0);
        }
                     
     }
    return $query_args;
}

Can you please confirm it works as expected now:
=> hidden link

#2628925
צילום מסך 2023-08-01 ב-8.02.12.png

Hi
Thanks you
I doesn;t work is expected. As you see in the image, it shows 0 results for each category, and it show 2 sets of filters, one under the other.
If I switch to the backup toolset view I created yesterday before opening the ticket "writing-tasks-b-backup" everything works fine (but view shows posts as default before filtering, which is what I want to solve)
Thanks
Ron

#2628939

Minesh
Supporter

Languages: English (English )

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

Its due to AJAX and you will have to use the option "Full page refresh when visitors click on the search button with input values auto-updating" as with AJAX there is limited option to cover this feature and your layout is broken.

I've adjusted the code added to "Custom Code" section as given under:

add_filter( 'wpv_filter_query_post_process', 'func_hide_result_until_search_perform', 10, 3 );
function func_hide_result_until_search_perform( $query, $view_settings, $view_id ) {
     
  if ($view_id==60685 and !empty( $query->posts ) and !isset($_REQUEST['wpv_view_count'])  ) { 

        $final_result = array();
        $query->posts = $final_result; 
        $query->found_posts = count($final_result); // modify the count of found posts
        $query->post_count = count($final_result); // modify the count of displayed posts
    }
    return $query;
}

Can you please confirm it works as expected: hidden link

#2628941
צילום מסך 2023-08-01 ב-9.56.39.png

HI
As seen in the attached image:
filters raw is presented twice.
next to each category number of avaiaialble posts is presented (good!) but clicking on it does'nt show any posts

#2628973
צילום מסך 2023-08-01 ב-11.19.31.png

Hi
Now it works - I had to peress the "Search" bottom, since you disabled Ajax
It still show one filter raw above and one bellow results. Can you reomve the bottom one.

#2629017

Minesh
Supporter

Languages: English (English )

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

Can you please check now. I've removed the additional filter that used to display at bottom of the search result.

#2629321
צילום מסך 2023-08-02 ב-6.26.29.png

Hi
I will need also to make sure that the original view, with the Ajax and no hiding, is working properly.
vieew
So I switched to the original view but now it shows to filter lines, above and bellow the posts, as seen in the image,
pls. remove also here the 2nd line of filters.
writing-taks-view-b-backup
Thanks

#2629555

Minesh
Supporter

Languages: English (English )

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

I've removed the bottom filter line from your following view:
- hidden link