Tell us what you are trying to do? It works fine on the Locator page however there is a problem with the home page Portfolio I think because of the same custom code. If a user chooses a color say Red the wines show up as they should. Now if a user then clicks refresh the page comes up with No items found... So perhaps the Custom code needs to be applied to only the Locator page and not the entire site? Not sure how to do this...
Is there any documentation that you are following?
Is there a similar example that we can see?
What is the link to your site?
Hi,
Thank you for contacting us and I'd be happy to assist.
To troubleshoot this, I'll need to see how this view and the custom code are set up in the admin area.
Can you please share temporary admin login details along with the link to the locator page and the homepage?
Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.
regards,
Waqar
Thank you for sharing these details.
I've removed the existing custom code:
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
//add_filter( 'wpv_filter_query', 'func_disp_empty_view', 10, 3 );
function func_disp_empty_view($query_args, $setting, $views_id) {
if($views_id == 102728){
if(defined( 'DOING_AJAX') and DOING_AJAX ) {
foreach($_POST['search']['dps_general'] as $k=>$v):
if(
($v['name']=='wpv-wpcf-state' and $v['value']=='')
or
($v['name']=='wpv-relationship-filter' and $v['value']==0)
){
$query_args['post__in'] = array(0);
}
endforeach;
}
}
return $query_args;
}
add_filter( 'wpv_filter_query_post_process', 'prefix_modify_empty_query', 10, 3 );
function prefix_modify_empty_query( $query, $view_settings, $view_id ) {
if(defined( 'DOING_AJAX') and DOING_AJAX ) {
foreach($_POST['search']['dps_general'] as $k=>$v):
if(
($v['name']=='wpv-wpcf-state' and $v['value']=='')
or
($v['name']=='wpv-relationship-filter' and $v['value']==0)
){
$query->posts = array(); // add the default post to the posts result array
$query->found_posts = 0; // modify the count of found posts
$query->post_count = 0; // modify the count of displayed posts
}
endforeach;
} else if(isset($_GET['wpv_view_count'])) {
$query->posts = array(); // add the default post to the posts result array
$query->found_posts = 0; // modify the count of found posts
$query->post_count = 0; // modify the count of displayed posts
}
return $query;
}
And replaced it only with the relevant code, so that it only works for the view "Finder" ( ID: 102728 ), that you're using on the finder page:
add_filter( 'wpv_filter_query_post_process', 'prefix_modify_empty_query', 10, 3 );
function prefix_modify_empty_query( $query, $view_settings, $view_id ) {
if ($view_id == 102728)
{
if(defined( 'DOING_AJAX') and DOING_AJAX )
{
foreach($_POST['search']['dps_general'] as $k=>$v):
if(
($v['name']=='wpv-wpcf-state' and $v['value']=='')
or
($v['name']=='wpv-relationship-filter' and $v['value']==0)
){
$query->posts = array(); // add the default post to the posts result array
$query->found_posts = 0; // modify the count of found posts
$query->post_count = 0; // modify the count of displayed posts
}
endforeach;
}
else if(isset($_GET['wpv_view_count']))
{
$query->posts = array(); // add the default post to the posts result array
$query->found_posts = 0; // modify the count of found posts
$query->post_count = 0; // modify the count of displayed posts
}
}
return $query;
}
Please check both the views on those pages and see if that works.
Thanks. The home page Portfolio works well now however, the finder (locator) page has an issue if you choose a Wine and a State it is fine but if you hit refresh the view disappears. Also on a Product page in the product template (you get to this by clicking on a wine on the home page) if you go to Buy Now and select a State the view is correct until you go back to Select and then all the shop in the country show up it should be blank until a new State is selected.
Thanks for writing back.
To troubleshoot and assist you with both these points, I'll need to perform some tests on my server.
Do I have your permission, to download your website's clone/snapshot for this investigation? This way your live website won't be affected.
Yes you have my permission thank you.
Thank you for the permission.
Based on my tests, I've updated the code snippet from Minesh and duplicated it for both the views:
( i.e. view "Finder" with ID "102728" and view "Buy Now Specific Wine" with ID "102455" )
// code for the view "Finder" with ID "102728"
add_filter( 'wpv_filter_query_post_process', 'prefix_modify_empty_query_102728', 10, 3 );
function prefix_modify_empty_query_102728( $query, $view_settings, $view_id ) {
if ($view_id == 102728)
{
if(defined( 'DOING_AJAX') and DOING_AJAX )
{
foreach($_POST['search']['dps_general'] as $k=>$v):
if(
($v['name']=='wpv-wpcf-state' and $v['value']=='')
or
($v['name']=='wpv-relationship-filter' and $v['value']==0)
){
$query->posts = array(); // add the default post to the posts result array
$query->found_posts = 0; // modify the count of found posts
$query->post_count = 0; // modify the count of displayed posts
}
endforeach;
}
}
return $query;
}
// code for the view "Buy Now Specific Wine" with ID "102455"
add_filter( 'wpv_filter_query_post_process', 'prefix_modify_empty_query_102455', 10, 3 );
function prefix_modify_empty_query_102455( $query, $view_settings, $view_id ) {
if ($view_id == 102455)
{
if(defined( 'DOING_AJAX') and DOING_AJAX )
{
foreach($_POST['search']['dps_general'] as $k=>$v):
if(
($v['name']=='wpv-wpcf-state' and $v['value']=='')
){
$query->posts = array(); // add the default post to the posts result array
$query->found_posts = 0; // modify the count of found posts
$query->post_count = 0; // modify the count of displayed posts
}
endforeach;
}
}
return $query;
}
These changes take care of both the points that you mentioned about the views used on the locator page as well as the single product page.
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
Thank you but aside from Portfolio, the other pages are doing the same thing and not fixed. In Locator (finder) if a user selects a Wine and State the view is correct. When the user returns the Wine and State to Select (the default) and hits refresh all the shops in CT appear, which is odd. On the Product Template if a user selects a State the correct shops show, but again if a user returns to the default Select then hits refresh, all stores show in the country...
Can you please check those 2 pages again? I've made some more changes to the code snippet:
// code for the view "Finder" with ID "102728"
add_filter( 'wpv_filter_query_post_process', 'prefix_modify_empty_query_102728', 10, 3 );
function prefix_modify_empty_query_102728( $query, $view_settings, $view_id ) {
if ($view_id == 102728)
{
if(defined( 'DOING_AJAX') and DOING_AJAX )
{
foreach($_POST['search']['dps_general'] as $k=>$v):
if(
($v['name']=='wpv-wpcf-state' and $v['value']=='')
or
($v['name']=='wpv-relationship-filter' and $v['value']==0)
){
$query->posts = array(); // add the default post to the posts result array
$query->found_posts = 0; // modify the count of found posts
$query->post_count = 0; // modify the count of displayed posts
}
endforeach;
}
if(isset($_GET['wpv_view_count']))
{
if( (empty($_GET['wpv-wpcf-state'])) || (empty($_GET['wpv-relationship-filter'])) )
{
$query->posts = array(); // add the default post to the posts result array
$query->found_posts = 0; // modify the count of found posts
$query->post_count = 0; // modify the count of displayed posts
}
}
}
return $query;
}
// code for the view "Buy Now Specific Wine" with ID "102455"
add_filter( 'wpv_filter_query_post_process', 'prefix_modify_empty_query_102455', 10, 3 );
function prefix_modify_empty_query_102455( $query, $view_settings, $view_id ) {
if ($view_id == 102455)
{
if(defined( 'DOING_AJAX') and DOING_AJAX )
{
foreach($_POST['search']['dps_general'] as $k=>$v):
if(
($v['name']=='wpv-wpcf-state' and $v['value']=='')
){
$query->posts = array(); // add the default post to the posts result array
$query->found_posts = 0; // modify the count of found posts
$query->post_count = 0; // modify the count of displayed posts
}
endforeach;
}
if(isset($_GET['wpv_view_count']))
{
if( empty($_GET['wpv-wpcf-state']) )
{
$query->posts = array(); // add the default post to the posts result array
$query->found_posts = 0; // modify the count of found posts
$query->post_count = 0; // modify the count of displayed posts
}
}
}
return $query;
}
My issue is resolved now. Thank you!