Skip Navigation

[Resolved] View display with public filters – force filter choice before showing results.

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 7 replies, has 2 voices.

Last updated by lesleeM 1 year, 8 months ago.

Assisted by: Minesh.

Author
Posts
#2603491

We have a view that has two filters on it. We would like the results from this view to show no results until a filter is chosen. It currently shows ALL results and the filters only limit the results.

I found this previous ticket:

https://toolset.com/forums/topic/how-to-require-user-to-select-at-least-one-parameter-in-custom-search/

I wanted to try to emulate that code using our filter fields, but ran into a problem. First issue is that our filters are not done on taxonomies, so I'm not sure if this code will even work for us. One of our filters is done using a custom field. The other is a dropdown list of post titles pulled through post IDs that you helped us set up previously. See code here for our two filters in the view.

-----------------------------------------------------

<div class="form-group">
<label for="wpv-wpcf-ride-start-county" style="font-weight: bold;">[wpml-string context="wpv-views"]Filter Rides by County[/wpml-string]</label>
[wpv-control-postmeta type="checkboxes" field="wpcf-ride-start-county" url_param="wpv-wpcf-ride-start-county"]
</div>
<div class="form-group">
<label for="ride-post-id" style="font-weight: bold;">[wpml-string context="wpv-views"]Select Ride by Name[/wpml-string]</label>
[wpv-view name="ride-post-titles-dropdown"]
</div>

-----------------------------------------------------

So for the purposes of using your code provided in that other support ticket, I'm thinking that I'd need to define the county field as follows:

( isset($_GET['wpv-wpcf-ride-start-county']) && $_GET['wpv-wpcf-ride-start-county'] != '0' )

But then I'm not clear on how I'd define the second filter. That is not a field. Would I just use

( isset($_GET['ride-post-id']) && $_GET['ride-post-id'] != '0' )

In the query filter section of the view, this filter is defined as:

Post ID filter
Include only posts with IDs determined by the URL parameter "wpv-ride-post-id" eg. yoursite/page-with-this-view/?wpv-ride-post-id=1

So I'm not sure if I should use

( isset($_GET['wpv-ride-post-id']) && $_GET['wpv-ride-post-id'] != '0' )

Or do I need to do something else with this? Any help you can provide will be appreciated.

#2603887

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Before going any further its important to know that are you using full page refresh for your view or you are using ajax result update.

Can you please share problem URL where you added your view and once I review that I'm happy to share the filter code that should help you to fix your issue.

In addition to that - Could you please send me debug information that will help us to investigate your issue.
=> https://toolset.com/faq/provide-debug-information-faster-support/

#2604083

The page where we have the view we want to edit is located here:

hidden link

I'm not sure on full page refresh or ajax result update.

The admin page for the view is here:
hidden link

And the admin page for the view that creates the Select Ride By Name dropdown is here:
hidden link

We want this Ride Maps page to not show any results until someone chooses a County or a specific ride name. We're going to have hundreds of rides on this page, so the page will be too huge if all results are shown by default. It may even be too huge to show results by county, so I may still have to do more to tighten up the results display later. The Start Location field is the one making each entry take up multiple lines, so I may decide to change that to make it to where there won't be as much scrolling involved to see the full page. But for now, I just want to get it to where no results display until the end user makes a filter choice.

Thanks for the assistance.

#2604085

OK, I now see the setting in the view.

It is set to:

Full page refresh when visitors click on the search button

#2604275

Minesh
Supporter

Languages: English (English )

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

It seems I will require login access to get your view.

To hide results on view load you need to add following code to "Custom Code" section offered by Toolset or to the current theme's functions.php file:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

For example:

add_filter('wpv_filter_query', 'wpv_show_season_by_default', 99, 3);
function wpv_show_season_by_default( $query_args, $view_settings, $view_id ) {
    
    if($view_id == 99999 ){
         if( !isset($_GET['wpv_view_count']))  {
            $query_args['post__in'] = array(0);
        }
                    
     }
    return $query_args;
}

Where:
- replace 99999 with your original view id.

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

#2604579

The custom code you provided worked! You can see the results here:

hidden link

I changed wpv_show_season_by_default to wpv_no_results_by_default.

Do you still need admin access?

#2604661

Minesh
Supporter

Languages: English (English )

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

No - if its working. You're welcome to mark resolve this ticket.

#2604841

My issue is resolved now. Thank you!