Problem: I have a View that loops over child posts and outputs each child post's taxonomy terms. I end up with quite a few duplicates I would like to remove from the list of terms.
Solution: In order to break apart the taxonomy terms, you must use spans and separators in the wpv-post-taxonomy shortcode like this:
<wpv-loop> <div> <h6><span class="genre-string">[wpv-post-taxonomy type="category" separator=", </span><span class='genre-string'>" format="name" order="asc"]</span></h6> </div> </wpv-loop>
Then add some JavaScript to your View's JS panel:
jQuery(document).ready(function(){ var seenGenre = {}; // loop over spans jQuery('.genre-string').each(function(index,item) { var txt = jQuery(item).text(); var $div = jQuery(item).closest('div'); // if genre has been seen, remove this span if (seenGenre[txt] || seenGenre[txt + ', ']){ jQuery(item).remove(); }else{ seenGenre[txt] = true; } // now reexamine the parent div and see if it should be removed for lack of content if($div.text() == ''){ $div.remove(); } }); });
Relevant Documentation: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-taxonomy
Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 5 replies, has 2 voices.
Last updated by taih 6 years, 7 months ago.
Assisted by: Christian Cox.
The forum ‘Types Community Support’ is closed to new topics and replies.