Why does the theme insert the comments section if I don't reset my custom WP_Query?

I have a bit of an odd situation. I have somehow solved it, but I'm trying to understand why my solution works.

I'm using TheBuilt, a theme that uses Visual Composer. I have extended Visual Composer with a custom element that I use to display a custom posts page (the main loop is not in use on that page, nor is any other custom loop). In order to build a posts object, I create a new WP_Query object that looks like this:

$categories_ids = '3,5' //examplary values
$query = array(
  'post_type' = 'post',
  'cat' = $categories_ids,
  'taxonomy' = 'category',
  'orderby' = 'date',
  'order' = 'DESC'
);

$posts = new WP_Query($query);

I then use the $posts object with get_the_title, get_permalink() et c. to build html blocks. However, when I added that element to a page, the theme rendered the comments section below the page content even though I had Allow Comments unchecked in the page options. I found that this does not happen when I evoke wp_reset_query() in my shortcode function before I return the html block.

Why is that? What exactly does wp_reset_query() do in this situation? Does it unset some variable or destroy my post object, which the theme might check to decide wether to display the comments section? I checked the wordpress codex and it explicitly states the folowing:

Because we are using new WP_Query we aren't stomping on the original $wp_query and it does not need to be reset with wp_reset_query()

The theme is professional-grade and as far as I can tell rather well written, so I don't think it's just a bug in the theme, but rather some functionality or interaction I'm missing (which is why I ask this here and not in the theme support forums) ...

Topic wp-reset-query wp-query Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.