title: Get Posts Based on Category Wordpress
body: <p>I have two categories in WordPress. One is events and another one is news. I have to fetch posts in two categories in same page. There is only 4 posts in news category. And events can add to user. I have to display first 8 events based on the date of post. I am writing both categories using two queries and moving to an array.</p>
  
  <p>I've coded for this as given below:</p>
  
  <pre><code>$event_title       = array();
  $event_author      = array();
  $event_content     = array();
  $event_thumbnail   = array();
  $event_counter     = 0 ;
  
  $arg = array(
      'numberposts' =&gt; 8,
      'offset' =&gt; 0,
      'category' =&gt; 17,
      'orderby' =&gt; 'post_date',
      'order' =&gt; 'ASC',
      'post_type' =&gt; 'post',
      'post_status' =&gt; 'draft, publish, future, pending, private',
      'suppress_filters' =&gt; true
  );
  
  $events = new WP_Query( $arg );
  
  if ($events-&gt;have_posts()) : while ($events-&gt;have_posts()) : $events-&gt;the_post(); 
  
  $event_title[$event_counter]        = get_the_title();
  $event_author[$event_counter]       = get_the_author();
  $event_content[$event_counter]      = get_the_content();
  $event_thumbnail[$event_counter]    = get_the_post_thumbnail();
  
  $event_counter++;
  
  endwhile; endif;
  </code></pre>
  
  <p>the category id for events is 17, I've find the id using the method <code>echo get_cat_ID( "events" );</code></p>
  
  <p>the problem here is the posts are not fetched on the basis of category. it takes first 8 posts withou considering the category. how can I solve this issue.</p>