Hey,
Is there a way I can divide search results by category/taxonomy?
For example:
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
I tried creating a separate view for each category then placed all 4 views search results in one page. it worked, but if I now want to filter out just 1 category, I can't, since they are always in the same place.
Any ideas?
Cheers!
Ido
Hi, there's not a built-in way to group results like this this with Views. I assume your 4 Views are filtered by a taxonomy term, using a URL parameter, correct? You could try to use 4 different Views like you described, and combine that with conditional HTML that tests the URL parameter used for your taxonomy filter:
[wpv-conditional if="( '[wpv-search-term param='wpv-tax-param']' eq 'articles' )"]
Articles View here
[/wpv-conditional]
[wpv-conditional if="( '[wpv-search-term param='wpv-tax-param']' eq 'videos' )"]
Videos View here
[/wpv-conditional]
Replace 'wpv-tax-param' with whatever URL parameter you're using, and replace 'articles' and 'videos' with whatever the URL parameter value is when that term is selected in the filter.
thx C!
i made separate views and inserted them into a larger view, like you suggested. but the page doesn't load for hours, like there's a loop problem there somehow.
maybe i need to create a certain filter for each smaller view? like "parent view"?
thanks!
ido
I would not insert the 4 Views inside another View, I would insert them directly into a Post, Page, Content Template, or Layout Visual Editor cell. Can you take screenshots showing each View editor in wp-admin? I would like to see how you have the Query Filters configured. Then also take a screenshot showing how all 4 Views are placed on your site.
yes, i've tried that and it works - the only thing is i can't use ajax like that. i have to refresh the page.
and THEN i have to place submit buttons...
hey again,
ok - so forget ajax 🙂 still have a problem.
i want:
1. that the relevant view will appear initially, before there was any filter made
2. that i would be able to filter 2 types together
my code now is:
[wpv-conditional if="( '[wpv-search-term param='wpv-post-typer']' ne 'video' ) AND ( '[wpv-search-term param='wpv-post-typer']' ne 'video' )"]
{!{wpv-view name='article-searcher' view_display='layout'}!}
[/wpv-conditional]
[wpv-conditional if="( '[wpv-search-term param='wpv-post-typer']' ne 'articles' ) AND ( '[wpv-search-term param='wpv-post-typer']' ne 'audio' )"]
{!{wpv-view name='video-searcher' view_display='layout'}!}
[/wpv-conditional]
[wpv-conditional if="( '[wpv-search-term param='wpv-post-typer']' ne 'articles' ) AND ( '[wpv-search-term param='wpv-post-typer']' ne 'video' )"]
{!{wpv-view name='audio-searcher' view_display='layout'}!}
[/wpv-conditional]
i can achieve goal 1, but i can't achieve goal 2, because when i'm filtering 2 types togehter the url parameter changes from:
hidden link
to:
hidden link
and the condition fails.
Yes, the code I provided earlier was not intended to support multiple selections. This custom shortcode can test the presence of a value in a URL parameter with multiple values:
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.
Here's a document showing how to implement custom shortcodes in a conditional:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/