Tell us what you are trying to do?
We are offering a legal compliance service to our clients. One of the components of this service is a list or table containing a big number of laws with supplementary information. Some of these lists in different variants, we use for ourselves, they may contain over 2'100 posts or laws respectively. To facilitate the loading of these views, we apply a custom code, so that the page containing the view is first loaded, and then the view is only displayed, if the user selects one of the custom filters. This has become possible based on the following custom script:
<?php
/**
* Zeigt einen View erst, wenn ein Filter ausgewählt ist. Funktioniert für Gesetzesliste. Aus Toolset Hilfe
https://toolset.com/forums/topic/how-to-show-no-initial-results-on-a-view-until-a-filter-is-set/
bezieht sich auf die Gesetzesliste Kunden GaPa
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){
$target_views = array(41691,30836,41764,41749,43134,43140,41739); // 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'] ) && !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 works fine for all the views listed with their ID's in the snippet. BUT the last one, ID 41739, is an 'archive organisation', which means: each client has a specific role or organisation taxonomy, called 'organisation'. When the client logges in, he will be able to see HIS SPECIFIC LIST OF LAWS. Each law is assigned to specific clients or organisation. So this archive is a WordPress archive and is not based on a Toolset-query.
At the end we would like to have the same behaviour for this archive as for the 'non-archive pages and views'. But it does not work, the view is loaded even if no filter is selected. Can the snippet be adapted for archives also?
Is there any documentation that you are following?
The above code is coming from the Toolset Support, thank you! The views are constructed with the legacy view.
Is there a similar example that we can see?
no, but I can leave you our credentials, so you can see the details
What is the link to your site?
rechtskonform.ch