Hello I have a query that gets a post with id=x and it works but it leaves out the comment box.
Is there a way to add “get comment box” to the query?
<?php
$post_id = 104;
$queried_post = get_post($post_id);
$content = $queried_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
?>
First of all, welcome to WPSE!
By default, the comment box does not come with the post object, what you are looking for is the
comments_template
function.It should be as simple as changing your code to this:
But if I’m correct this would only work for the current post in the loop.
Looking at the function in
wp-includes/comment-template.php
, it usesglobal $post
andglobal $wp_query
variables. You would need to modify that value in order for the comments template to show up for the post you are displaying.You could modify that using
query_posts
instead ofget_post
, but be sure to reset the query afterwards:I haven’t tested this but it should work. I would also suggest reading this awesome answer by Rarst about when to use what function to “get posts”. 🙂
With this query you can add the comments.