title: What is the query using the $wpdb notation that would allow to search and potentially echo posts from certain categories?
body: <p>Unfortunately my MySQL skills became quite rusty for complex queries and combined with my lack of experience in WordPress I have to succumb to asking for help.</p>
  
  <p>Here is a further explanation of the question:</p>
  
  <p>I am currently trying to modify a core WordPress(3.91) included calendar widget functions ( is located in wordpress\wp-includes\general-template.php)  so that the calendar shows only the posts from a category group created by me ( Lets call it Events for now).</p>
  
  <p>I AM GOING TO USE MODIFIED VERSION IN A SEPARATE FILE AS A WIDGET KEEPING CORE FILES INTACT AS THEY WERE!!!!!!!!!!!!!!!!!!!!!!!!!!</p>
  
  <p>So we have:</p>
  
  <ol>
  <li><p>a core function that checks if there were any posts made:</p>
  
  <pre><code>$gotsome = $wpdb-&gt;get_var("SELECT 1 as test FROM $wpdb-&gt;posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
  </code></pre></li>
  <li><p>and a core function that makes the appropriate date available to click ( e.g. creates a hyper-link to list of events on that date)</p></li>
  </ol>
  
  <p><strong>Get days with posts</strong> </p>
  
  <pre><code>$dayswithposts = $wpdb-&gt;get_results("SELECT DISTINCT DAYOFMONTH(post_date)
      FROM $wpdb-&gt;posts WHERE post_date &gt;= '{$thisyear}-{$thismonth}-01 00:00:00'
      AND post_type = 'post' AND post_status = 'publish'
      AND post_date &lt;= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
  if ( $dayswithposts ) {
      foreach ( (array) $dayswithposts as $daywith ) {
          $daywithpost[] = $daywith[0];
      }
  } else {
      $daywithpost = array();
  }
  
  if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
      $ak_title_separator = "\n";
  else
      $ak_title_separator = ', ';
  
  $ak_titles_for_day = array();
  $ak_post_titles = $wpdb-&gt;get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
      ."FROM $wpdb-&gt;posts "
      ."WHERE post_date &gt;= '{$thisyear}-{$thismonth}-01 00:00:00' "
      ."AND post_date &lt;= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
      ."AND post_type = 'post' AND post_status = 'publish'"
  );
  if ( $ak_post_titles ) {
      foreach ( (array) $ak_post_titles as $ak_post_title ) {
  
              /** This filter is documented in wp-includes/post-template.php */
              $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title-&gt;post_title, $ak_post_title-&gt;ID ) );
  
              if ( empty($ak_titles_for_day['day_'.$ak_post_title-&gt;dom]) )
                  $ak_titles_for_day['day_'.$ak_post_title-&gt;dom] = '';
              if ( empty($ak_titles_for_day["$ak_post_title-&gt;dom"]) ) // first one
                  $ak_titles_for_day["$ak_post_title-&gt;dom"] = $post_title;
              else
                  $ak_titles_for_day["$ak_post_title-&gt;dom"] .= $ak_title_separator . $post_title;
      }
  }
  </code></pre>
  
  <p>I have found some similar solutions however not entirely appropriate for my situations here:</p>
  
  <ol>
  <li><p><a href="http://wordpress.org/support/topic/mysql-query-for-all-posts-in-news-category-id-problem?replies=1" rel="nofollow noreferrer">link1</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/20971729/how-to-get-all-posts-with-all-categories-in-wordpress-through-mysql">link2</a></p></li>
  </ol>
  
  <p>To sum up:</p>
  
  <p>How should I change those queries for my means try to keep it to a maximum to $wpdb notation.</p>
  
  <p>Thanks in advance guys and girls</p>