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!
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 */
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?
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);
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!
OK, please let me know if you need more assistance for it. thanks
I am able to display the views programmatically within the custom post type's "single" file. Thank you!