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
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/
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 );
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.
thanks, I am going another way