I want to detect if a content template is assigned to a post and conditionally enqueue a script.
Works if content template is manually selected for each newly created post.
Does not seem to work if content template is dynamically assigned to a custom post type via the 'Usage' settings.
$post_id = get_the_ID();
$ct_id = get_post_meta( $post_id, "_views_template", true );
if ( $ct_id == 22244 || $ct_id == 30330 ) {
wp_enqueue_script( 'section-nav-script', get_stylesheet_directory_uri() . '/assets/js/dist/section-nav.js', array(), CHILD_THEME_VERSION );
}

Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Chris,
Thank you for getting in touch.
You should be able to make use of the function below to check the content template that is assigned to a particular post.
https://toolset.com/documentation/programmer-reference/views-api/#has_wpv_content_template
This provides an exact solution for your use case.
Thanks,
Shane
My issue is resolved now. Thank you!