Problem: I have a Content Template assigned to single Location posts. If the post has the term "Seasonal" applied in the Location Services taxonomy, I would like to display a different Content Template.
Solution: Use the following custom code to programmatically switch Content Templates automatically based on post type, term assignment, and type of Content Template.
//Apply a specific Content Template to posts in a specific post type with a specific term from a specific taxonomy add_filter( 'wpv_filter_force_template', 'ts_force_template_for_seasonal', 99, 3 ); function ts_force_template_for_seasonal( $template_selected, $id, $kind ) { $post_type = 'location'; $term_slug = 'seasonal'; $taxonomy_slug = 'taxonomy-slug'; $alternate_template_id = 123; // do not edit below this line if ( get_post_type( $id ) == $post_type && has_term( $term_slug, $taxonomy_slug, $id ) && $kind == 'single-location' ) { $template_selected = $alternate_template_id; } return $template_selected; }
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template
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 19 replies, has 2 voices.
Last updated by 5 years, 7 months ago.
Assisted by: Christian Cox.