Skip Navigation

[Resolved] How to set initial default dropdown View Output blank instead of All posts

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

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

Last updated by ClementB7865 3 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#2203691

Tell us what you are trying to do? Trying to reinitiate blank view if a user selects default dropdowns. Essentially, default dropdown should be set to None rather than All posts.

To do so, as per my prior ticket request, I wrapped the View Loop in Conditional :

NOT ( empty( '[wpv-search-term param='wpv_view_count']') )

This works when a user first loads the page and has not made a dropdown selection. But once they make a selection, the view never resets to blank even though both dropdowns are returned to their initial default selection. This is a deal killer for me for this software if a solution cannot be easily implemented.

Is there any documentation that you are following? Looked through every ticket on this subject without resolution.

Is there a similar example that we can see? After reading through so many support tickets, it seems like this is a very popular request None vs All with the norm being None not All as it seems to be set now. None would be the norm for not making a selection. Was the Toolset code written backwards? Any plans to add this to the next release?

What is the link to your site?

#2204469

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share problem URL and steps I should follow to see the issue.

As I understand - you would like to display no result if both dropdown are set to defeat option "please select" is that correct?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2205857

Minesh
Supporter

Languages: English (English )

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

I checked and I can see that you are using the AJAX filter view and you select the option "AJAX refresh when changing any filter" that means whenever you will change the filter it will update the result and that is expected and this is how it used to work by default.

If you want that until and unless user select values from the both the dropdown then you will have to select the option "Full page refresh when clicking Submit" or "AJAX refresh when clicking submit" and you will require to add the "Submit" button to your search form.

#2205981

But really the issue is the same. Using a submit button doesn't solve the problem. The problem with the Toolset default configuration is that it is choosing ALL as default not NONE. So in your example it works the same way if I use a submit button. Because once a user goes back to Default setting (option 1 in the dropdown box) the view results will be ALL products or all shops depending on the page. It should be NONE. The better solution for Toolset would be to give us the option of choosing whether we want the user to see default ALL items or NONE. So once again, until Toolset gets on board with this option I need the ability to make that happen. Default must be NONE not all items. Please let me know how I accomplish that and I guarantee you will be solving this for many Toolset purchasers that have requested the exact same thing.

#2205987

Minesh
Supporter

Languages: English (English )

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

Can you please tell me - Did you added any view's filter so that it does not displaying any results on initial page load? If yes - Can you please tell me where you added that code?

OR

Tell me how you are not displaying the result on initial page load?

#2206027

Yes, in both Locator page and Template for Products I use a conditional block in the View Output which is:

NOT ( empty( '[wpv-search-term param='wpv_view_count']') )

This was provided by another Support Team Member. However it only works the first time a user comes to the page once they do a search and then go back and try the default Select it shows ALL items again....

#2206079

Minesh
Supporter

Languages: English (English )

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

Can you please check now: hidden link

I've added the following filter code to "Custom Code" section offered by Toolset:
=> hidden link

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;
}

Can you please confirm it works as expected.

More info:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

#2206083

At the start yes, but, after doing an initial search if I return to Select (default option) there are no other dropdowns just Select, the rest have disappeared.

#2206099

Minesh
Supporter

Languages: English (English )

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

Can you please check now: hidden link

I've disable the previous hook and added the following hook to "Custom Code" section offered by Toolset:

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;
      } 
      
       
    
    return $query;
}

Does this works as expected?

#2206113

Excellent! Looks great thank you! Would it be possible to change the "No items found" to blank "" since in my database there always will be a result.

#2206115

Minesh
Supporter

Languages: English (English )

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

I've removed the "No Items Found" text as you can see from the section as you can see with the following screenshot:
=> hidden link

Glad to help and happy to resolve your issue 🙂 Have a great time 🙂

You are welcome to mark resolve this ticket.

#2206119

I still see No items found on my site...

#2206121

Also, I found if the user refreshed the page we are back to square one with ALL shops being displayed despite the default Select on both Wine and State...

#2206123

Minesh
Supporter

Languages: English (English )

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

I just forget to hit save button :).

Can you please refresh the page and check again.

#2206125

Minesh
Supporter

Languages: English (English )

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

Does "No Items Found" text is gone?