Skip Navigation

[Resolved] Displaying a Content Template Programmatically does not render contained views

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

Problem:

I am able to render this content template programmatically using PHP codes, but the problem is that none of the shortcode, which contains the views, are not rendering any of the dynamic data.

Solution:

You will need to setup the variable $post value, for example:

https://toolset.com/forums/topic/displaying-a-content-template-programmatically-does-not-render-contained-views/#post-1235383

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/views-api/#render_view_template

This support ticket is created 5 years, 9 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: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by tech-opsE 5 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#1235326

I am creating a function where I want to render a content template that I have created within the CMS. I am able to render this content template programmatically but the problem is that none of the shortcode, which contains the views, are not rendering any of the dynamic data.

Code:

$filtered_posts = render_view_template(12345, $post);
echo $filtered_posts;

Output:

/* Content Here */
[wpv-post-body view_template=”None”] [wpv-view name=”group-view-dynamic” limit=”-1″]
/* More Content Here */

I have conducted a couple of experiments where I've placed my code in both shortcodes.php and a custom class to see if this data can render the views properly but they are still not being displayed.

Any help would be greatly appreciated!

#1235380

Hello,

This should be a copy/paste problem:
In your shortcodes, the double quotes character has been change to another character ”, I suggest you try these:
Edit the content template, replace the view's shortcode as below:

/* Content Here */
[wpv-post-body view_template="None"] [wpv-view name="group-view-dynamic" limit="-1"]
/* More Content Here */
#1235382

My code actually does contain the regular double quotes characters. I think when I copied the shortcodes from my output, my browser just displayed them differently.

The views within this content template are actually rendered properly when using the content template within a custom post in the actual WordPress Admin CMS for that post.

The problem is when I try to use either the render_view or render_view_template functions programmatically, that's when the views do not get rendered within the files shortcodes.php or functions.php.

Should these functions be placed in a specific file somewhere else?

#1235383

That depends on your custom PHP codes, it seems you need to put your custom PHP codes insider a post loop, where I have tested my codes I mentioned above in theme file single.php, it works fine.

And you will need to setup the variable $post value, for example:

global $post;
echo $filtered_posts = render_view_template(52, $post);
#1235384

Ok, I will try putting this code within one of my custom post type template files such as single-customgroup.php

I will let you know of my progress, thank you!

#1235442

OK, please let me know if you need more assistance for it. thanks

#1236697

I am able to display the views programmatically within the custom post type's "single" file. Thank you!