I'm using wp_enqueue_script to selectively load .js files. When conditions are used to enqueue for specific pages or post, is_page or is_single are working fine but I'm struggling to implement a condition for post edit content templates.
I've tried
if ( is_single('view-template') )
if ( is_single('my-custom-post-type') )
if ( is_single('123') )
if ( is_single('cred-form') )
but none of them work. The script loads if I remove the condition which confirms the rest of the snippet is OK.
If you want to target the views template, views template is stored as postmeta in postmeta table with key "_views_template" which holds the content template ID as meta value.
So, if you want to check for example for post ID 9999 what content template ID is assigned. you should fetch the content template ID as:
$post_id = 9999;
$views_ct_id = get_post_meta($post_id,'_views_template',true);
If($views_ct_id===XXX){
// do your things here
}
I'm sorry but I don't understand how I would use this to enqueue a .js file. If I want my .js file to be loaded for a specific custom post type, I would write this:-
so if it needs to load for a content template, I would expect to replace 'my-custom-post-type' with 'view-template' because that is the "post type" from the posts table (not postmeta) but that doesn't work.