Skip Navigation

[Resolved] drop down showing all results on load

This support ticket is created 4 years, 10 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 8 replies, has 2 voices.

Last updated by davidP-26 4 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1535183

Tell us what you are trying to do?
I have 2 dropdown lists on the site and when page is loaded, all results from the database are shown.
I need the opposite functionality, on load only dropdown list should be shown and when the user selects the item in dropdown, data is displayed below.

What is the link to your site?
hidden link
password: factory

1st example
hidden link
Internationale Partner on the right side (below the map), very long list of partners is shown

2nd example
hidden link
Applications below, all applications are show, but we want only dropdown on start without the list.

#1535343

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand - with the dropdown select filter you mentioned with both the examples you want to display only options which those dropdowns which are available as a result - correct? If yes:

Can you please navigate to the section "Custom Search Settings" on the edit view page - try to select the option:
- Let me choose individual settings manually
-- further, select the option "Show only available options for each input"

Does this help to resolve your issue?

#1535425

Hello, the functionality of the dropdown is OK (Ajax on change).

The problem is that I dont't want to show all results when the page is loaded. There should be no result on page load after the dropdown, results shoul be shown only when the user selects an option from the dropdown.

#1535489

Minesh
Supporter

Languages: English (English )

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

Ok - I understood. By default, you do not want to display any results.

Can you please try to add the following code to your current theme's functions.php file
or
You can add it to the "Custom Code" section offered by the Toolset:
=>

add_filter( 'wpv_filter_query', 'show_empty_default_func', 10, 3 );
     
function show_empty_default_func( $query_args, $setting,$view_id ) {
	
    if($view_id == 1226 or $view_id == 1294){
		
              if(!defined('DOING_AJAX') and !isset($_POST['action'])) {
				$query_args['post__in'] = array(0);
           } 
      
    }
    return $query_args;
}

Where:
- 1226 and 1294 is your original view ID.

However - you also need to change the "Custom Search Settings " to:
- Let me choose individual settings manually
- and further within the section "Which options to display in the form inputs", select "Always show all values for inputs".

Please check the following screenshot.
=> hidden link

#1535585

Great, it works now!

But there is another problem. I have some CSS aplied to adjust font size and margins and this function broke the CSS that is applied in the View template using built in CSS editor.

I managed to apply broken css via styles.css, but is there a way to use built in Views css editor in this case?

#1535587

Minesh
Supporter

Languages: English (English )

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

Great - Glad to know that the solution I shared helps you to resolve your original issue.

May I kindly ask you to open a new ticket with your every new question you may have. This will help other users searching on the forum as well as help us to write correct problem resolution summery. Thank you for understanding.

#1535601

Is it a new ticket? CSS broke after applying custom code in functions.php, so it is related.

#1535609

Minesh
Supporter

Languages: English (English )

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

Ok - I've split the ticket and we will handle that new related issue with the following ticket. I will followup there.
=> https://toolset.com/forums/topic/split-drop-down-showing-all-results-on-load-css-broken-after-filter-hook-applied/

You may close this ticket.

#1535613

My issue is resolved now. Thank you!