The problem
You must remember to call the core function wp_reset_postdata()
, after your while loop, to restore the global $post
object. The comment form is relying on that object, that you override with your $queryPosts->the_post()
call.
Note that the extract()
isn’t recommended, check this answer by @toscho, for example.
Removing comments
To remove the comment form, when using a shortcode, you could check out my answer here.
If you want to remove the list of comments and the comment-form, after the shortcode, then you can try out one the following methods, within the shortcode’s callback:
Method #1 Remove the queried comments via filters:
if( is_singular() && post_type_supports( get_post_type(), 'comments' ) )
{
// Remove the comment form
add_filter( 'comments_open', '__return_false' );
// Remove the list of comments
add_filter( 'comments_array', '__return_empty_array' );
}
Method #2 Force get_comments()
to return an empty array:
if( is_singular() && post_type_supports( get_post_type(), 'comments' ) )
{
// Remove the comment form
add_filter( 'comments_open', '__return_false' );
// Empty comments SQL query - Run only once
add_filter( 'comments_clauses', function( $clauses )
{
static $count = 0;
if( 0 === $count++ )
$clauses['where'] .= ' AND 1=0 ';
return $clauses;
});
}
Here we run the filter callback only once, to prevent this from e.g. a recent comments widget in the sidebar.
Method #3 Modify the comment template via filter. Create an empty file comments-empty.php
within your theme and use:
if( is_singular() && post_type_supports( get_post_type(), 'comments' ) )
{
// Modify the comment template
add_filter( 'comments_template', function( $template )
{
if( $tmp = locate_template( 'comments-empty.php' ) )
$template = $tmp;
return $template;
} );
}
You can modify the file path to your needs.
Method #4 Hide it with CSS. Example:
if( is_singular() && post_type_supports( get_post_type(), 'comments' ) )
{
print '<style> #comments { display: none } </style>';
}