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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
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)
Este tema contiene 3 respuestas, tiene 2 mensajes.
Última actualización por hace 6 años, 3 meses.
Asistido por: Christian Cox.