Problem: I have 4 categories: articles, video, audio, events.
I am searching for free text "basketball".
I want the results to show:
Results for "basketball" under "articles":
article-1, article-2, article 3
Results for "basketball" under "videos":
video-1, video-2, video-3
Results for "basketball" under "audio":
audio-1, audio-2, audio-3
Results for "basketball" under "events":
event-1, event-2, event-3
Solution:
There is not a good way to split up a single custom search View this way. Instead, you could use 4 separate custom search Views, each filtered by a single term. Then you can use conditional HTML to show and hide each View based on a URL parameter.
Add this custom shortcode to inspect URL parameters:
function exists_in_repeating_url_param_func($atts) {
$var = $atts['var'];
$test = $atts ['test'];
$exists = isset($_GET[$var]) ? in_array( $test, $_GET[$var] ) : 0;
return $exists;
}
add_shortcode("exists_in_repeating_url_param", "exists_in_repeating_url_param_func");
Use it like this:
[exists_in_repeating_url_param var="wpv-post-typer" test="video"]
If the URL includes "wpv-post-typer%5B%5D=video", this shortcode will return 1. If not, the shortcode will return null. You can use the value of this shortcode to determine whether or not to display each View.
Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/