Tell us what you are trying to do?
I'm trying to display a page's content in a popup. I'd like to show the whole content with the content template also. I'm using the "new WP_Query" method to create a loop, where I select the page_id argument to show only the desired page. The get_the_content function is only returning the post body, without the content template.
Is there any documentation that you are following?
I have not found any documentation for this job.
Is there a similar example that we can see?
There is no example.
What is the link to your site?
Here is the page, where I'm showing markers on an image:
hidden link
If you click on any marker, a popup will show up with this page's content:
hidden link
As you can see, the page has other content also, which is displayed with a content template.
Please let me know, how can I display the entire content of a page (without header and footer and other parts of the page. Only the content with the content template.
Thank you!
To call a Content Template you can use the API here:
https://toolset.com/documentation/programmer-reference/views-api/#render_view_template
For example the code below will show the post $my_post with the CT ID 80
echo render_view_template( 80, $mypost );
Thank you Beda for your help! I just found the same solution, which is working for me.
I have a problem with it. There are php notices about this function:
Notice: Trying to get property 'post_author' of non-object in /wp-content/plugins/wp-views/embedded/inc/wpv-api.php on line 262
The problem here is, that in that code, you want to use the $post as an object, but it is not. It is only an id of a user. So you need to fix this to get the user id with get_post_field function. Just change the 261-262. lines in the wpv-api.php file to this:
$authorid = get_post_field( 'post_author', $post_in );
$authordata = new WP_User( $authorid );
I am not entirely sure what you mean.
Can you share the code you use to throw the notice?
If you echo a render_view_template( 80, $mypost ); and $mypost is really a Post object, it works just fine, I tried it.
Of course, if you pass anything else in $mypost, the ID of the post as an example, then you get an error:
Notice: Trying to get property 'post_author' of non-object in /Applications/MAMP/htdocs/stable/wp-content/plugins/wp-views/embedded/inc/wpv-api.php on line 262
Call Stack
But, that is not a BUG, as you need to pass the Post Object, to the function, not the Post ID or any else.
Example (Working):
global $post;
echo "start";
echo render_view_template( 12, $post );
echo "end";
Do I misunderstand you?
Yes, you are right, I was passing the ID, instead of the object. Thank you!