Tell us what you are trying to do?
trying to have no results display as the intial result for a relationship filter in a post view
Is there any documentation that you are following?
ive tried the solution provided by nigel :
this works for view id 679 but does not work for id 694
function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){
$target_views = array(679,694); // Edit to add IDs of Views to add this to
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 );
but this does not work for this filter.
Is there a similar example that we can see?
no
What is the link to your site?
the page with issue is here
hidden link
Hello and thank you for contacting the Toolset support.
I am not sure to understand what you try to do. Can you elaborate more?
From the code provided, I would say that it empties the query results when ALL these conditions are met:
- !isset( $query_results->query['meta_query'] ) = No custom field is used in the query.
- !isset( $query_results->query['tax_query'] ) = No taxonomy is used in the query.
- !isset( $query_results->query['s'] ) = No search term is used in the query.
Without knowing more about your use case, I would be helpless.
this code doesnt work for "Post Relationship" type filters.
did you look at the page?
what more would you like to know? this code was provided by nigel on multiple support threads and does exactly as i want on a view that filters by tax or other type filter but not on the filter i am using
so here is the page that works properly with the code provided by nigel:
hidden link
this is using an ajax search filter
[wpv-control-post-taxonomy taxonomy="faq-category" default_label="Select a Category of FAQ" type="select" url_param="wpv-faq-category"]
here is the page that doesnt work even with adding the view ID to the array in nigels code:
hidden link
this is using post control filters
[wpv-control-post-relationship ancestors="contact-list@contact-contact-list.child" url_param="wpv-relationship-filter"]
and
[wpv-control-post-ancestor type="select" ancestor_type="contact-list@contact-contact-list.child"]
when you go to the faq page nothing displays until you select it
when you go to the paralegal division contacts results display without having to select anything.
does that clear it up?
Thank you for your feedback. I would say that one fo the conditions is not met and the code is not executed. This needs debugging to have a confirmation.
I would like to investigate a copy of your website locally and find out why the code is not run. If you agree, your next reply will be private to share a Duplicator package download link or credentials to your website to take a copy manually.
Please take a backup before sharing credentials.
Hello and my apologies for the late reply. I do not work on Mondays.
I took a UpdraftPlus backup of your website and I am debugging it locally. I'll get back to you as soon as I found something.
I asked assistance from my team about this particular view/page (/contact-pages/paralegal-division-contacts/) and we were able to get what is desired without custom code.
Nigel suggested to wrap the loop content inside a conditional such as below:
[wpv-items-found]
<!-- wpv-loop-start -->
[wpv-conditional if="( '[wpv-search-term param='wpv_view_count']' ne '' )"]
<!-- your loop content here -->
[/wpv-conditional]
<!-- wpv-loop-end -->
[/wpv-items-found]
And this was working for this page on my local setup.
The custom code was already only bound to another view, not "694"
$target_views = array(679); // Edit to add IDs of Views to add this to
This is the ticket where Nigel has suggested this solution https://toolset.com/es/forums/topic/mensaje-inicial-en-view/#post-1348103
Let me know if this solution is working for you.
no this doesnt work. it doesnt load on initial page load but after changing the selection it loads even if the default option is picked.
I also know that the code from nigel is not currently bound to 694 it didnt work so i took that view id out of the array. you have a copy you should be able to add it in the array and see that while it works for view 679 exactly as advertised it does not work for view 694 and in fact breaks the view and prevents any info from being loaded
Hello,
I can see that the provided solution does not work after we choose a filter and then we choose none.
Please check this function on your site, it worked for me:
function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){
$target_views = array(679); // Edit to add IDs of Views to add this to
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;
}
}
if ( $view_id === 694 ) { // used in "/contact-pages/paralegal-division-contacts/"
if ( isset( $_GET['wpv-relationship-filter'] ) && ( $_GET['wpv-relationship-filter'] == 0 ) ) {
$query_results->posts = array();
$query_results->post_count = 0;
$query_results->found_posts = 0;
}
}
return $query_results;
}
Note the condition that is set for (view_id === 694).
My issue is resolved now. Thank you!