title: How to Add Category Filter in WordPress Post Query
body: <p>I filtered the post's in my sidebar by using this code, </p>
  
  <pre><code>$mostlikequerystr = "
  SELECT $wpdb-&gt;posts.* 
  FROM $wpdb-&gt;posts, $wpdb-&gt;postmeta
  WHERE $wpdb-&gt;posts.ID = $wpdb-&gt;postmeta.post_id 
  AND $wpdb-&gt;postmeta.meta_key = 'most_liked' 
  AND $wpdb-&gt;posts.post_status = 'publish' 
  AND $wpdb-&gt;posts.post_type = 'post'
  ORDER BY $wpdb-&gt;postmeta.meta_value DESC
      LIMIT 0 , 10";
  </code></pre>
  
  <p>This code working perfect , but now i want to add a category filter too..</p>
  
  <p>for this i used $term_id</p>
  
  <pre><code>global $wpdb;
  $term_id = get_term_by('slug','trailers');
  $term_id-&gt;term_id;
  echo $term_id;//Prints 12 
  $mostlikequerystr="SELECT $wpdb-&gt;posts.*  FROM $wpdb-&gt;posts,$wpdb-&gt;postmeta
  INNER JOIN $wpdb-&gt;term_relationships ON ($wpdb-&gt;posts.ID = $wpdb-&gt;term_relationships.object_id)
  INNER JOIN $wpdb-&gt;term_taxonomy ON ($wpdb-&gt;term_relationships.$wpdb-&gt;taxonomy_id = $wpdb-&gt;term_taxonomy.term_taxonomy_id)
  WHERE ($wpdb-&gt;term_taxonomy.term_id = $term_id 
  AND $wpdb-&gt;posts.ID = $wpdb-&gt;postmeta.post_id 
  AND $wpdb-&gt;postmeta.meta_key = 'most_liked'
  AND $wpdb-&gt;term_taxonomy.taxonomy = 'categories'
  AND $wpdb-&gt;posts.post_type = 'post'
  AND $wpdb-&gt;posts.post_status = 'publish')
          LIMIT 0 , 10";
  
          $tariler_post = $wpdb-&gt;get_results($mostlikequerystr, 'OBJECT');
           echo $wpdb-&gt;show_errors();
  </code></pre>
  
  <p>but its not working for me and no error too ...</p>