Problem: I have a View of child posts displayed on a parent post page. I would like to show a list of all the terms from a specific taxonomy that are associated with all the child posts in the View.
Solution:
Create a View of child posts filtered by post relationship, where the parent post is set by the current page. Insert this View into the parent post's Content Template.
Create a View of the taxonomy filtered by term ID, where the term is set by the current post in the loop. In the Loop output editor, use the following code to produce a comma-separated list of term IDs:
<wpv-loop> [wpv-item index=1] [wpv-taxonomy-id] [wpv-item index=other] ,[wpv-taxonomy-id] </wpv-loop>
Add this code to your functions.php file to strip out all the extra markup from these results:
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 ); function prefix_clean_view_output( $out, $id ) { $ids = array( 12345 ); if ( in_array( $id, $ids )) { $start = strpos( $out, '<!-- wpv-loop-start -->' ); if ( $start !== false && strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false ) { $start = $start + strlen( '<!-- wpv-loop-start -->' ); $out = substr( $out , $start ); $end = strrpos( $out, '<!-- wpv-loop-end -->' ); $out = substr( $out, 0, $end ); } else { $start = strpos( $out, '>' ); if ( $start !== false) { $out = substr( $out, $start + 1 ); $end = strpos( $out, '<' ); $out = trim(substr( $out, 0, $end )); } } } return $out; }
Replace 12345 with the numeric ID of this View of Taxonomy.
Then create a second View of the taxonomy, filtered by term ID, provided by a shortcode attribute "terms". In the Loop Output of this View, include whatever you want to display for each term. There will be no duplicates in this View, even though the filter contains duplicate IDs.
Finally, nest the first View in the terms shortcode attribute of the second View:
[wpv-view name="second-view-slug" terms="[wpv-view name='first-view-slug']"]
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 |
---|---|---|---|---|---|---|
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 3 replies, has 3 voices.
Last updated by 6 years, 7 months ago.
Assisted by: Christian Cox.