title: WordPress: How to filter posts by category using $wp_query?
body: <p>I built a custom theme on WordPress with a static front page and no page set in <strong>Settings > Reading Settings > Front page displays</strong> as a posts page. I'd like to display posts, however, based on their categories throughout the site on different static pages. Therefore, I will never declare a posts index page through the console. And so I use the $wp_query function.</p>
  
  <p>How can I add a filter to this script that only displays posts in the category "apples" (for example)? Right now, this script shows all posts regardless of category.</p>
  
  <pre><code>&lt;?php
      $temp = $wp_query;
      $wp_query = null;
      $wp_query = new WP_Query();
      $wp_query-&gt;query('showposts=1' . '&amp;paged='.$paged);
      while ($wp_query-&gt;have_posts()) : $wp_query-&gt;the_post();
  ?&gt;
  
  &lt;h2&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="Read"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;
  &lt;?php the_excerpt(); ?&gt;
  &lt;?php the_date(); ?&gt;
  
  &lt;?php endwhile; ?&gt;
  
  &lt;?php if ($paged &gt; 1) { ?&gt;
      &lt;p&gt;&lt;?php previous_posts_link('Previous page'); ?&gt;
      &lt;?php next_posts_link('Next page'); ?&gt;&lt;/p&gt;
  &lt;?php } else { ?&gt;
      &lt;p&gt;&lt;?php next_posts_link('Next page'); ?&gt;&lt;/p&gt;
  &lt;?php } ?&gt;
  
  &lt;?php wp_reset_postdata(); ?&gt;
  </code></pre>