title: Wordpress RSS feed template with custom wp_query
body: <p>I have written my own rss template with WP_Query, but it doesn't work as intended. Here is the code:</p>
  
  <pre><code>&lt;?php
  header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
  $more = 1;
  
  echo '&lt;?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . '&gt;';
  
  /**
   * Fires between the xml and rss tags in a feed.
   *
   * @since 4.0.0
   *
   * @param string $context Type of feed. Possible values include 'rss2', 'rss2-comments',
   *                        'rdf', 'atom', and 'atom-comments'.
   */
  do_action('rss_tag_pre', 'rss2');
  ?&gt;
  &lt;rss version="2.0"
       xmlns:content="http://purl.org/rss/1.0/modules/content/"
       xmlns:wfw="http://wellformedweb.org/CommentAPI/"
       xmlns:dc="http://purl.org/dc/elements/1.1/"
       xmlns:atom="http://www.w3.org/2005/Atom"
       xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
       xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
      &lt;?php
      /**
       * Fires at the end of the RSS root to add namespaces.
       *
       * @since 2.0.0
       */
      do_action('rss2_ns');
      ?&gt;
      &gt;
  
      &lt;channel&gt;
          &lt;title&gt;&lt;?php bloginfo_rss('name');
              wp_title_rss(); ?&gt;&lt;/title&gt;
          &lt;atom:link href="&lt;?php self_link(); ?&gt;" rel="self" type="application/rss+xml"/&gt;
          &lt;link&gt;&lt;?php bloginfo_rss('url') ?&gt;&lt;/link&gt;
          &lt;description&gt;&lt;?php bloginfo_rss("description") ?&gt;&lt;/description&gt;
          &lt;lastBuildDate&gt;&lt;?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?&gt;&lt;/lastBuildDate&gt;
          &lt;language&gt;&lt;?php bloginfo_rss('language'); ?&gt;&lt;/language&gt;
          &lt;sy:updatePeriod&gt;&lt;?php
              $duration = 'hourly';
  
              /**
               * Filter how often to update the RSS feed.
               *
               * @since 2.1.0
               *
               * @param string $duration The update period. Accepts 'hourly', 'daily', 'weekly', 'monthly',
               *                         'yearly'. Default 'hourly'.
               */
              echo apply_filters('rss_update_period', $duration);
              ?&gt;&lt;/sy:updatePeriod&gt;
          &lt;sy:updateFrequency&gt;&lt;?php
              $frequency = '1';
  
              /**
               * Filter the RSS update frequency.
               *
               * @since 2.1.0
               *
               * @param string $frequency An integer passed as a string representing the frequency
               *                          of RSS updates within the update period. Default '1'.
               */
              echo apply_filters('rss_update_frequency', $frequency);
              ?&gt;&lt;/sy:updateFrequency&gt;
          &lt;?php
          /**
           * Fires at the end of the RSS2 Feed Header.
           *
           * @since 2.0.0
           */
          do_action('rss2_head');
  
          $query_args = array(
              'post_type' =&gt; 'post',
              'order' =&gt; 'DESC',
              'orderby' =&gt; 'date',
              'meta_query' =&gt; array(
                  'relation' =&gt; 'OR',
                  array(
                      'key' =&gt; 'votes',
                      'value' =&gt; '10',
                      'compare' =&gt; '&gt;=',
                      'type' =&gt; 'NUMERIC',
                  ),
                  array(
                      'key' =&gt; 'author_role',
                      'value' =&gt; array('administrator', 'contributor', 'editor', 'author'),
                      'compare' =&gt; 'IN',
                  ),
              ),
              'post_status' =&gt; 'publish'
          );
  
          $query = new WP_Query($query_args);
  
          if ($query-&gt;have_posts()) :
              while ($query-&gt;have_posts()) :
                  $query-&gt;the_post();
                  ?&gt;
                  &lt;item&gt;
                      &lt;title&gt;&lt;?php the_title_rss() ?&gt;&lt;/title&gt;
                      &lt;link&gt;&lt;?php the_permalink_rss() ?&gt;&lt;/link&gt;
                      &lt;comments&gt;&lt;?php comments_link_feed(); ?&gt;&lt;/comments&gt;
                      &lt;pubDate&gt;&lt;?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?&gt;&lt;/pubDate&gt;
                      &lt;dc:creator&gt;&lt;![CDATA[&lt;?php the_author() ?&gt;]]&gt;&lt;/dc:creator&gt;
                      &lt;?php the_category_rss('rss2') ?&gt;
  
                      &lt;guid isPermaLink="false"&gt;&lt;?php the_guid(); ?&gt;&lt;/guid&gt;
                      &lt;?php if (get_option('rss_use_excerpt')) : ?&gt;
                          &lt;description&gt;&lt;![CDATA[&lt;?php the_excerpt_rss(); ?&gt;]]&gt;&lt;/description&gt;
                      &lt;?php else : ?&gt;
                          &lt;description&gt;&lt;![CDATA[&lt;?php the_excerpt_rss(); ?&gt;]]&gt;&lt;/description&gt;
                          &lt;?php $content = get_the_content_feed('rss2'); ?&gt;
                          &lt;?php if (strlen($content) &gt; 0) : ?&gt;
                              &lt;content:encoded&gt;&lt;![CDATA[&lt;?php echo $content; ?&gt;]]&gt;&lt;/content:encoded&gt;
                          &lt;?php else : ?&gt;
                              &lt;content:encoded&gt;&lt;![CDATA[&lt;?php the_excerpt_rss(); ?&gt;]]&gt;&lt;/content:encoded&gt;
                          &lt;?php endif; ?&gt;
                      &lt;?php endif; ?&gt;
                      &lt;wfw:commentRss&gt;&lt;?php echo esc_url(get_post_comments_feed_link(null, 'rss2')); ?&gt;&lt;/wfw:commentRss&gt;
                      &lt;slash:comments&gt;&lt;?php echo get_comments_number(); ?&gt;&lt;/slash:comments&gt;
                      &lt;?php rss_enclosure(); ?&gt;
                      &lt;?php
                      /**
                       * Fires at the end of each RSS2 feed item.
                       *
                       * @since 2.0.0
                       */
                      do_action('rss2_item');
                      ?&gt;
                  &lt;/item&gt;
              &lt;?php endwhile; ?&gt;
          &lt;?php endif; ?&gt;
          &lt;?php wp_reset_postdata(); ?&gt;
          &lt;?php wp_reset_query(); ?&gt;
      &lt;/channel&gt;
  &lt;/rss&gt;
  </code></pre>
  
  <p>Everything works fine, but I get random content for each post (<code>get_the_content_feed('rss2');</code> function returns random content). How can I fix this?</p>