Skip Navigation

[Resolved] Content Template for single page of different taxonomy

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

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 1 reply, has 2 voices.

Last updated by Christian Cox 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1357065

This thread is exactly what I'm trying to do but I can't see the hidden content and I'm afraid my reply on that thread might not be answered since it's closed:
https://toolset.com/forums/topic/content-template-for-single-page-of-different-taxonomy/#post-1356559

I have a custom post type "providers" and I have 2 content templates, basic & member. In my provider content template I have taxonomy for both basic and member profiles so if you select basic taxonomy, I'd like the basic content template to apply and same for member.

Heres' my url:
hidden link
Some of the posts have basic or member taxonomy checked in the admin already.

#1357307

Hi, it looks like most of these hidden links point to old demo sites have long since been deleted. There's a cleaner solution that involves a small snippet of custom code. Our API filter wpv_filter_force_template can be used to programmatically adjust the Content Template applied to some post on-the-fly, based on any logic you want to use. Here's an example:

//Show a specific Content Template for providers posts, based on the taxonomy terms applied
add_filter( 'wpv_filter_force_template', 'tssupp_basic_member_template_switch', 99, 3 );
  
function tssupp_basic_member_template_switch( $template_selected, $id, $kind ) {
    if ( $kind == 'single-providers' ) {
        if ( has_term( 'member-term-slug', 'taxonomy-slug', $id) ) {
          $template_selected = 123;
        }else if ( has_term( 'basic-term-slug', 'taxonomy-slug', $id) ) {
          $template_selected = 456;
        }
    }
    return $template_selected;
}

You'll have to adjust this code to work with your site's setup:
- You may need to change providers to match the custom post type slug for the Providers post type, if it isn't indeed providers
- Change member-term-slug to match the slug of the Member taxonomy term
- Change basic-term-slug to match the slug of the Basic taxonomy term
- Change taxonomy-slug to match the slug of the taxonomy that holds the Member term and the Basic term
- Change 123 to match the numeric ID of the Content Template you want to display for Members.
- Change 456 to match the numeric ID of the Content Template you want to display for Basic.

Add that updated code to your child theme's functions.php file, or create a new custom code snippet in Toolset > Settings > Custom Code.
Let me know if you get stuck and I can take a closer look. Here's the documentation for this filter:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template