Skip Navigation

[Resolved] Create nested views as select dropdowns

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

Problem:
[wpv-layout-start]... [wpv-layout-end] will render an extra div tag
Solution:
You can try create a custom shortcode to hide codes you don't need, for example:
1) add codes in your theme/functions.php:

add_shortcode('hide-it', 'hide_it_func');
function hide_it_func($atts, $content) {
    return;
}

2) edit your view, modify the codes as below:

[hide-it][wpv-layout-start][/hide-it]
...
[hide-it][wpv-layout-end][/hide-it]

Relevant Documentation:

This support ticket is created 8 years 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)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Joff 7 years, 12 months ago.

Assisted by: Luo Yang.

Author
Posts
#373242

I am trying to create a View that displays the values of a nested taxonomy as Select dropdown elements.

My taxonomy is created as such:

Option 1
- Option 1.1
- - Option 1.1.1
- Option 1.2
- - Option 1.2.1
Option 2
- Option 2.1
Option 3
- Option 3.1
etc

I would like to output three Select dropdowns, where the choice of each populates the next Select element.

So choosing Option 1 from the first dropdown would populate the second dropdown with:
- Option 1.1
- Option 1.2

Then, choosing Option 1.1 from the second dropdown, it would populate the third dropdown with:
- - Option 1.1.1

I've tried to create this with three separate Taxonomy Views (Level 1, Level 2, Level 3), filtered by "Select taxonomy terms whose parent is the value set by the parent view", then each "Level x" view is included within the parent view, however this isn't working as desired.

Can you advise on how to achieve this in Views please?

#373650

Dear Joff,

Thanks for the details, there isn't such a build-in feature within Views, and there are lots of similar request from other client, and here is the feedback from our main developers of Views:
WordPress has a flag when searching for posts belonging to a taxonomy term, when the taxonomy is hierarchical. That flag stated whether we should include in the search results the items that belong to any children term of the curently used (even if posts are not assigned directly to it) or not. Besides that, people have very different ways of adding terms on a hierarchical taxonomy to posts: some of them add the whole tree from parent to children, some add only the children.

The result of all this is that we can not provide a consistent behavior at all, and any implementation will have people asking for the other way around. So this is a no-go.

So there isn't any plan to apply it into Views plugin, but I added your thread into our to-do list, hope it can raise the attention.

#380039

Hi Luoy,

Thanks for explaining the problems with building this into Views, I agree the usage of hierarchical taxonomies is unpredictable!

I'm looking at using JS as a different approach - can you advise on whether I can create a View that simply outputs all taxonomy entries in the relevant hierarchy, with a prefix for the child elements?

E.g.
Taxonomy value 1
--Taxonomy value 1.1
--Taxonomy value 1.2
Taxonomy value 2
--Taxonomy value 2.1
etc.

Thanks,
Joff

#380041

Further to this, I've got a partially working solution with a nested View:

View-Parents:

[wpv-layout-start]
        [wpv-items-found]
        <select>
                <!-- wpv-loop-start -->
                <wpv-loop>
                        <option value="[wpv-taxonomy-slug]">[wpv-taxonomy-title]</option> 

                        [wpv-view name="view-children"]
      
                </wpv-loop>
                <!-- wpv-loop-end -->
        </select>
 	[/wpv-items-found]
[wpv-layout-end]

View-Children:

[wpv-layout-start]
	[wpv-items-found]
		<!-- wpv-loop-start -->
                <wpv-loop>
                        <option value="[wpv-taxonomy-slug]">--[wpv-taxonomy-title]</option>
                </wpv-loop>
		<!-- wpv-loop-end -->
	[/wpv-items-found]
[wpv-layout-end]

But the output HTML is invalid, is this because I'm nesting a wpv-loop within another wpv-loop?

<select>
    <!-- wpv-loop-start -->
    
      <option value="parent1">Parent1</option> 

</select>

<option value="Parent1Child1">--Parent1Child1</option>

#380048

The shortcode [wpv-layout-start] ... [wpv-layout-end] will output a extra HTML div tag, I suggest you try the solution of another thread to hide it:
https://toolset.com/forums/topic/i-need-the-ability-to-create-a-loop-without/#post-328540

#380347

Thanks Luoy, that's worked perfectly.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.