Skip Navigation

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

This support ticket is created 8 years, 5 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 14 replies, has 4 voices.

Last updated by kellyR 8 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#347513

I am trying to make my search results blank when users first arrive the page but it is showing all the results.

Here's the url: hidden link

I'm only using 1 filter which is the search box. I don't want to show any results until users use the search box to search for results.

#347571

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Views allow you to select option what should be display by default. You can able to display only parametric search form on one page and display the results on the another page.

=> https://toolset.com/documentation/user-guides/front-page-filters/
[See section "Displaying the Parametric Search View on the Site"]

#See following image:
hidden link
=> Select option "only search box"
=> on another page select option "only search result"

#347735

I don't see the option to show what to display by default. I don't want to show any results by default.

This is the closest thing I can find to this topic. I have set Parametric Search Settings to "AJAX results update when visitors click on the search button".

#347755

By the way, I want to display the results and search box all on 1 page. I don't want both to be separated.

#347797

Dear Stanley,

You can try Views filter hook wpv_filter_query, for example:
Add below codes in your theme/functions.php:

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

Please replace 546 with your view's ID

More help:
wpv_filter_query
When displaying a View listing posts, this filter is applied to the arguments being generated by the View settings before they are passed to the WP_Query class.
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/

#348068
wpviews.png

Hey luoy,
Good code! It works.
1 more question:
How can we replace the starting "No items found" message to something different?
Something like "Start your search here"

#348090

Please try this:
Edit the problem view, in section "Loop Output", find the string "No items found", replace it with what you needed.

#349902

Thanks Luoy, you solved the problem!
I got another question which is not related to this.
How do we make Views to sort the results by relevance?
Right now, we are sorting by A-Z which isn't really making sense for what we are doing.
It's like Google sorting their search results from A-Z.

#349915

Dear Stanley,

Could you create new thread for new question?
and describe details for the question "sort the results by relevance", thanks

#350275

1 more question, luoy.
I got 2 more views I want to display blank results as the starting page.
What should I do to modify the code for this?

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

You can modify it from:
$view_id == 546
To:
in_array($view_id, array(546, 123, 456));

More help:
in_array — Checks if a value exists in an array
hidden link

#350408
sort.png

It worked!
1 more thing I found, the $ is not sorting correctly. I have attached a screenshot.
I'm trying to sort but Views is not sorting correctly.
Views is only sorting by the 1st digit.

Update: I also change my custom field to Types control numeric but the sort is still not working.

#350452

Dear Stanley,

Could you create new thread for new question? it will help other users to find the answers.

Also describe detail steps to duplicate same problem, for example, how do you setup the custom field "Average salary", what value do you store into the custom field "Average salary", how do you setup the views's option of sortby, thanks

#350472

Ok. Thread opened.

#559318

I am using 1 taxonomy for search criteria. This workaround does not work for me. It removes all items from the search form's dropdown selector, which results in 'no items found' but renders the search form unusable.
I would like to know how to hide initial results for a search form. Initial results are not needed, I could just use a view for that display.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.