Problem: I have a View that shows Pages (a hierarchical post type). I would like to show a random Page, filtered by a post ancestor. Any descendant Pages of that ancestor should be shown by the View.
Solution: Use a custom shortcode to generate a comma-separated list of all the descendant post IDs:
function get_all_descendent_pages($atts) { global $post; $all_wp_pages = get_pages(); $descendent_pages = get_page_children( $post->ID, $all_wp_pages ); $ids = array(); foreach( $descendent_pages as $dp ) { array_push( $ids, $dp->ID ); } return implode(',', $ids); } add_shortcode("get-all-descendent-pages", "get_all_descendent_pages");
Place this shortcode on your ancestor Page:
[get-all-descendent-pages] //results: 123,456,789
Add this shortcode in Toolset > Settings > Front-end Content > Third-party shortcode arguments.
Use the custom shortcode to supply the value of a post IDs shortcode attribute for your View:
[wpv-view name="anderen-lezen-ook-nz" ids="[get-all-descendent-pages]"]
Change the View's Query Filter to filter by post ID, set by a shortcode attribute "ids".
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 2 voices.
Last updated by 6 years, 3 months ago.
Assisted by: Christian Cox.