Skip Navigation

[Resolved] How to filter nested views. Can't display full taxonomy for filters or results.

This support ticket is created 5 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 7 replies, has 2 voices.

Last updated by zachariahC 5 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1356491

Tell us what you are trying to do? On the page below, I have inserted 2 views. I'm not sure which one the client is going to want to go for so I would like to have both working as expected. In View 1, I am using nested views. There are two things I have been unable to figure out. The first is that the taxonomy values are not show the full taxonomy hierarchy. For example, the first one shown should be showing "Policies and Procedures > Racing" but what is is showing is "Racing" and then that document is repeated showing "Policies and Procedures" right below it. Same thing with the next 2. "Officials Resources" should be "Officials > Officials Resources" and "Officials" should not be there.

The other thing I need to do is filter out View 1 by the taxonomy so it only shows values from the selected taxonomy. Again, if possible, the select dropdown should show the complete hierarchical structure.

In View 2, the filtering dropdown is only showing the single taxonomy item but not its parent. Without that, the end user would have no idea which main category they are choosing.

Secondly, I was told to try using wpv-post-taxonomy in the loop to show the taxonomy for the results. Ideally I would like this to appear as a heading above the results if possible. However, for text searches this might be tricky and having a breadcrumb to the document might be workable. This is what I am using in the loop:

<div class="document">[wpv-post-taxonomy type="document-category" separator=" > "] [wpv-post-title]</div>

Is there any documentation that you are following? Yes. Looking at the shortcode references, searching the forum.

Is there a similar example that we can see?

What is the link to your site? hidden link

#1356615

Hello,

Q1) The first is that the taxonomy values are not show the full taxonomy hierarchy

I assume we are talking about the shortcode [wpv-post-taxonomy], see our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-taxonomy

There isn't such kind of feature to output terms as "full taxonomy hierarchy", in your case, you might consider custom codes.

And even with custom codes, there will be a problem if the post is assigned with multiple terms, for example: "Racing" + "Officials Resources".

Q2) The other thing I need to do is filter out View 1 by the taxonomy so it only shows values from the selected taxonomy. Again, if possible, the select dropdown should show the complete hierarchical structure.

I assume "View 1" is a nested view: Parent taxonomy + Child post view

If it is, Only Views listing posts can have custom search inputs., the taxonomy view does not support custom search form, so it does not support taxonomy select dropdown too.

Q3) I was told to try using wpv-post-taxonomy in the loop to show the taxonomy for the results. Ideally I would like this to appear as a heading above the results if possible.

Same as above, the shortcode [wpv-post-taxonomy] should be put into the post loop, it works for each post.

Since the dropdown "DOCUMENT CATEGORY" will pass URL parameter "wpv-document-category" to target page, for example:
hidden link

You can get the URL parameter value with Views shortcode [wpv-search-term], for example:
[wpv-search-term param="wpv-search-term"]

See our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-search-term

#1357225

Hi and thanks for the response. It is disappointing that filtering is not possible with nested views.

When you say "There isn't such kind of feature to output terms as "full taxonomy hierarchy", in your case, you might consider custom codes." what do you mean by custom codes? Custom codes that do what exactly and what would they look like?

One other question. I finally got the wpv-post-taxonomy working. But I'm trying to add in a conditional in there so that:
1. If someone filters the view via the dropdown, only the post titles are shown.
2. If someone uses the search form, both the post taxonomy and the post title are shown.

I tried to create a conditional using the following with the hopes that if the search term isn't empty, then it displays the taxonomy. If it is empty, then it doesn't show the taxonomy:

<div class="document">[wpv-conditional if="( '[wpv-search-term]' ne '' )"]<h3 class="taxonomy-title">[wpv-post-taxonomy type="document-category" format="name"]</h3>[/wpv-conditional]
[wpv-post-title]</div>

However, now it just doesn't ever show the taxonomy under either case. Can you help me with this conditional?

#1357491

Q1) what do you mean by custom codes? Custom codes that do what exactly and what would they look like?

I have searched it in google, and found some related threads, for example:
https://stackoverflow.com/questions/35958456/display-hierarchy-of-the-terms-for-the-current-post-wordpress
https://wordpress.org/support/topic/display-hierarchical-taxonomy-list/#post-3881067

For your reference.

Q2) If someone filters the view via the dropdown, only the post titles are shown.
If someone uses the search form, both the post taxonomy and the post title are shown.

As I mentioned above:

the dropdown "DOCUMENT CATEGORY" will pass URL parameter "wpv-document-category" to target page

https://toolset.com/forums/topic/how-to-filter-nested-views-cant-display-full-taxonomy-for-filters-or-results/#post-1356615

So you can get the URL parameter "wpv-document-category" value like this:
[wpv-search-term param="wpv-search-term"]

Then use above shortcode in [wpv-conditional], like this:

<div class="document">[wpv-conditional if="( '[wpv-search-term param="wpv-search-term"]' eq '' )"]<h3 class="taxonomy-title">[wpv-post-taxonomy type="document-category" format="name"]</h3>[/wpv-conditional]
<a href="[types field='document-file' output='raw'][/types]" target="_blank" rel="noopener noreferrer">[wpv-post-title]</a></div>
#1358081
image-2.jpg
image-1.jpg

Hi and thanks for your assistance. I didn't realize that when you said custom code, you were referring to general WordPress modifications. I thought you were referring to Toolset specific custom codes. That helps.

I tried using your view loop code but it isn't working either. Perhaps I didn't explain the problem clearly enough.

On this page: hidden link I have a select list for the taxonomy as well as a search box. If someone uses the select list, I don't want the the category to show up in the results. I've created what I am trying to do by modifying the view. Image 1 is what happens when someone uses the select. Image 2 is when someone uses the search box.

The code you provided me above, shows the results as in Image 2 for both situations. As well, in the views editor it indicates an error with the code in the param="wpv-search-term"]' section. The page URL reflects the difference between using the select box and the search box but I can't figure out how to use that as a conditions and either show or hide the document category in the <h3> tag.

#1358595

The code I mentioned above is just an example, please try to modify it as below:

<div class="document">[wpv-conditional if="( '[wpv-search-term param="wpv-document-category"]' eq '' )"]<h3 class="taxonomy-title">[wpv-post-taxonomy type="document-category" format="name"]</h3>[/wpv-conditional]
<a href="[types field='document-file' output='raw'][/types]" target="_blank" rel="noopener noreferrer">[wpv-post-title]</a></div>

And test again, if you need more assistance for it, please provide a test site with the same problem, fill below private message box with credentials, thanks

#1359337

Thanks for the details, I can log into your website and see the problem, when the URL parameter "wpv-document-category" is empty, the shortcode [wpv-search-term param="wpv-document-category"] outputs value 0, so I have modified the codes as below:

<div class="document">[wpv-conditional if="( '[wpv-search-term param="wpv-document-category"]' eq '' ) OR ( '[wpv-search-term param="wpv-document-category"]' eq '0' )"]<h3 class="taxonomy-title">[wpv-post-taxonomy type="document-category" format="name"]</h3>[/wpv-conditional]
<a href="[types field='document-file' output='raw'][/types]" target="_blank" rel="noopener noreferrer">[wpv-post-title]</a></div>

Please test again, check if it is fixed. thanks

#1359851

Thanks for all your help with this. Still learning how to use Toolset so this initial and ongoing help is very much appreciated to get through the learning curve.