Skip Navigation

[Resolved] How to get current post content template id in code?

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user would like to get the ID of the content template of a custom post in code.

Solution:
After the update to Toolset Blocks 1.5, we introduced a new way of handling single post pages with content templates. Now we have conditions and priorities to determine what content template to use on a post to display on its single post page. You will need to pass the post's object ($post) to it:

$template_id = apply_filters( 'wpv_content_template_for_post', 0, $post );
This support ticket is created 3 years, 4 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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by Alexander Rothschild 3 years, 4 months ago.

Assisted by: Jamal.

Author
Posts
#2154249

I'm writing a custom code snippet, where I need to add conditional logic based on the template used in the current post. I've seen the following global in the docs:

global $current_archive_template_id;

But that applies to the archive pages. Is there an equivalent for a singular post? Thanks!

#2154259

Hello and thank you for contacting Toolset Support.

After the update to Toolset Blocks 1.5, we introduced a new way of handling single post pages with content templates. Now we have conditions and priorities to determine what content template to use on a post to display on its single post page. You will need to pass the post's object ($post) to it:

$template_id = apply_filters( 'wpv_content_template_for_post', 0, $post );

However, this filter is not documented yet. Let me know if you have any further questions.

#2154385

Thanks Jamal. This is perfect!