Skip Navigation

[Resolved] Using filters to determine which Template Layout or Content Filter is used

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

Problem:
Which filter will prevail if trying to set a Layout or Content Template programmatically?

Solution:
The get_layout_id_for_render filter is a Layouts filter.

The wpv_filter_force_template filter is a Views filter.

You can use the get_layout_id_for_render filter to modify which Template Layout is used, or the wpv_filter_force_template filter to modify which Content Template is used, but you cannot use the filters to modify whether a Template Layout or Content Template is used, which will be determined by what you have set for the post type, or more specifically for the individual post.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template

This support ticket is created 6 years, 10 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by John Johansen 6 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#610832

Tell us what you are trying to do?

I want to understand why I would programmatically select a layout ('get_layout_id_for_render' filter) used by a template versus forcing a template ('wpv_filter_force_template' filter)
.
I have already employed the 'get_layout_id_for_render' filter to conditionally override the layout displayed by a given template. However, I need to know how this is fundamentally different than the 'wpv_filter_force_template' filter which forces the use of a particular template (which could use a particular layout).

Or, do these two filters simply provide a choice of how to do fundamentally the same thing?

Is there any documentation that you are following?
Layouts.

In another ticket (https://toolset.com/forums/topic/using-different-content-templates-for-the-same-cpt/), I asked for clarification on the assertion that a layout cannot be assigned programmatically.

Is there a similar example that we can see?
No
What is the link to your site?
N/A

#610985

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

The get_layout_id_for_render filter is a Layouts filter.

The wpv_filter_force_template filter is a Views filter.

Both Layouts and Views can be used to create templates ("Template Layouts" and "Content Templates").

Obviously, only one can be used at any one time.

When setting templates in the admin pages, if you assign both a Content Template and a Template Layout to a post type, Layouts prevails and the Template Layout will be used.

I haven't tested setting them programmatically, but I expect you will find that you can use the get_layout_id_for_render filter to modify which Template Layout is used, or the wpv_filter_force_template filter to modify which Content Template is used, but you cannot use the filters to modify whether a Template Layout or Content Template is used, which will be determined by what you have set for the post type, or more specifically for the individual post.

#611177

Nigel:
Thanks for your response.