Problem: I would like to apply different WordPress Archives to each level of hierarchy in a custom taxonomy.
Solution: Use the wpv_filter_force_wordpress_archive filter to programmatically specify different WordPress Archives based on the taxonomy term hierarchy level:
function get_tax_level($id, $tax){ $ancestors = get_ancestors($id, $tax); return count($ancestors)+1; } add_filter( 'wpv_filter_force_wordpress_archive', 'switch_tax_archive_by_level', 30, 2 ); function switch_tax_archive_by_level( $wpa_assigned, $wpa_loop ) { $wpa_to_apply = $wpa_assigned; $tax = get_queried_object() ? get_queried_object()->taxonomy : null; if ($tax == 'viagens') { $current_term_level = get_tax_level(get_queried_object()->term_id, get_queried_object()->taxonomy); if ($current_term_level == 1) { // show top-level archive $wpa_to_apply = 1761; } else if ($current_term_level == 2) { // show mid-level archive $wpa_to_apply = 1722; } else { // show third-level archive $wpa_to_apply = 1722; } } elseif ( is_home() ) { $wpa_to_apply = 1771; } return $wpa_to_apply; }
Relevant Documentation: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_wordpress_archive
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 22 replies, has 2 voices.
Last updated by 7 years, 2 months ago.
Assisted by: Christian Cox.