Skip Navigation

[Resolved] Search not working as expected

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

Problem:

If I just click search without selecting any filter I do not get any results and I guess we should get all.

Solution:

This is a custom codes issue, see details here:

https://toolset.com/forums/topic/search-not-working-as-expected-2/#post-2240611

Relevant Documentation:

This support ticket is created 3 years, 1 month 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)

This topic contains 4 replies, has 2 voices.

Last updated by camila 3 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#2240187
Screen Shot 2021-12-08 at 4.39.17 PM.png
Screen Shot 2021-12-08 at 4.38.28 PM.png

Hello.
we are using the block editor to set up a search on our site. It's searching first for a Post relationship or repeatable field groups owner and then for other custom fields. If I fill up all fields then I get results. But if I just click search without selecting any filter I do not get any results and I guess we should get all. The other issue is that if we select the Post relationship or repeatable field groups owner and then hit search we do not get any result but if we select another custom field we do.
any idea why this might be happening? please see img attached
thanks

#2240331

Hello,

You are right, it is supposed to return all posts if you did not filter anything, see our demo site:
hidden link
The "States" and "Cities" field are relationship filters, and it works fine after submit the submit button.

So the problem you mentioned above is abnormal, please check these:
1) In case it is a compatibility problem, please deactivate all other plugins, and switch to WordPress default theme 2021, deactivate all custom PHP/JS code snippets, and test again

2) If the problem still persists, please provide database dump file(ZIP file) of your website, you can put the package files in your own google drive disk, share the link only, also point out the problem page URL and view URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#2240611

Hi Luo,
thanks for your answer. I did some debugging and find out what the issue is. A while back we asked support for a way to hide the initial results in the search and they gave me the following code, I just removed the code and it's working as expected, can you please review the code and let me know what might be causing the issue? thanks

/**
* No initial results
*
* Don't show View results until a filter has been applied
*
* Tests for custom field filters, taxonomy filters, or text searches
**/

function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){

$target_views = array( 1295 ); // Edit to add IDs of Views to add this to

if ( in_array( $view_id, $target_views ) ) {

// is there a filter set?
if ( !isset( $query_results->query['meta_query'] ) && !isset( $query_results->query['tax_query'] ) && !isset( $query_results->query['s'] ) ) {
$query_results->posts = array();
$query_results->post_count = 0;
}
}

return $query_results;
}
add_filter( 'wpv_filter_query_post_process', 'tssupp_no_initial_results', 10, 3 );

#2241141

In your case, one filter can pass one URL parameter, you need to check each URL parameter(Exists and not empty), and skip the custom filter of your custom PHP codes.

#2242363

thanks, I am going another way