Skip Navigation

[Resolved] How to make default results blank for parametric search – continued?

This thread is resolved. Here is a description of the problem and solution.

Problem:
Show results only when a search parameter is selected. On page load no results should be shown, only Custom Search Form should be visible when we open page.

Solution:
Solution here with screenshots:
https://toolset.com/forums/topic/how-to-make-default-results-blank-for-parametric-search-continued/#post-588673

This support ticket is created 7 years 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.

Our next available supporter will start replying to tickets in about 2.14 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Matthias Reichl 7 years ago.

Assisted by: Noman.

Author
Posts
#587490

I am trying to: show results only when a search parameter is selected

Link to a page where the issue can be seen: hidden link

I expected to see: no results, BUT the select box should work

Instead, I got: no results and a select select box wich does not work

+++++++++++++++

I followed the instructions in this thread:
https://toolset.com/forums/topic/how-to-make-default-results-blank-for-parametric-search/
... and have the same problem as stated in the latest post in this thread

I added this code snippet:

add_filter( 'wpv_filter_query', 'default_blank_func', 10, 3 );
  
function default_blank_func( $query_args, $view_settings, $view_id ) {
    if ( $view_id == 9683 && !isset($_GET['wpv_post_search'])) { // if it is view 9683 and default result
         $query_args['post__in'] = array(0);
    }
    return $query_args;
}
#587514

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Rainer,

Thank you for contacting Toolset support. You can achieve this by using 2 pages, first page will have the Search form only and second page will have results and search filters (pre-selected from the previous page).

When you insert a Custom Search View into a page, it will give you option to separate form filters and results, and it will provide you with shortcode and instructions on how to add them separately, please follow the instructions given on screen.

We had another client who had the similar issue and was also able to solve it: https://toolset.com/forums/topic/display-only-the-search-box-but-the-results-in-another-place-on-the-same-page/

-- More info in this doc (section: 4.1. Adding the custom search form to a page or widget):
https://toolset.com/documentation/user-guides/front-page-filters/

-- Direct screenshot link: hidden link

Thank you

#588600

Hi Noman!

This does not solve my problem because I have to stay on the page.

A second idea to approach the problem.

Don't use the additional code snippet and supress the output (via conditional output) of the view if no taxonomy has been selected.

Is there a way to make a condition that the URL parameter "wpv-specialist-country" is empty?

Here is a page with the deactivated code snippet: hidden link

my current filter is:

[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="form-group">
	<label>[wpml-string context="wpv-views"]Specialist Countries[/wpml-string]</label>
	[wpv-control-post-taxonomy taxonomy="specialist-country" type="select" default_label="select Country" url_param="wpv-specialist-country"]
</div>
[wpv-filter-end]

my current loop output is:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
++++ here i would like to set a condition to show the content only if the URL parameter is not empty
		[wpv-post-title]<br>
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]
#588673

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

2.png
3.png

Hello Rainer,

Is there a way to make a condition that the URL parameter "wpv-specialist-country" is empty?
==> Yes, we can achieve this using small shortcode. Please add following code in your theme’s functions.php file:

add_shortcode('check_url_val', 'check_url_val_func');
function check_url_val_func() {
	if(isset($_GET['wpv-specialist-country']) && $_GET['wpv-specialist-country'] != '')
		return 1;
	else
		return 0;
}

2. Register shortcode first in Toolset >> Settings >> Front-end Content >> Third-party shortcode arguments sections -- screenshot attached for example.

3. We can add if condition in View >> ‘Filter and Loop Output Integration Editor’ as follows:

[wpv-conditional if="( '[check_url_val]' eq '1' )"]
[wpv-layout-meta-html]
[/wpv-conditional]

Please note: It may not work if you are using Ajax in your View. Toolset does not offer a builtin option to handle this feature on the same page, probably because of the complexity of handling all View’s options.

Thanks

#589067

Thank you, this perfectly did the job.

It did not, however work with AJAX, but this is not a problem.