title: WordPress Custom Query for Taxonomy
body: <p>I have to edit somebody's code and I am not familiar with querying posts using the method they are. I have tried editing the query to various alternatives, however I am having no luck. I want to change the following query to select data from a custom taxonomy called 'job_cat' where the value equals a POST value. The code is below:</p>
  
  <pre><code>$querystr = "
  SELECT DISTINCT wposts.*
  FROM $wpdb-&gt;posts wposts
  LEFT JOIN $wpdb-&gt;postmeta wpostmeta ON wposts.ID = wpostmeta.post_id
  LEFT JOIN $wpdb-&gt;postmeta wpostmeta2 ON wposts.ID = wpostmeta2.post_id
  LEFT JOIN $wpdb-&gt;term_relationships ON (wposts.ID = $wpdb-&gt;term_relationships.object_id)
  LEFT JOIN $wpdb-&gt;term_taxonomy ON ($wpdb-&gt;term_relationships.term_taxonomy_id = $wpdb-&gt;term_taxonomy.term_taxonomy_id)
  WHERE wp_term_taxonomy.term_id = 94";
  // If a job type is set and not equal to nothing or any jobs
  
  
  if(isset($_POST['search-location']) &amp;&amp; $_POST['search-location'] !== "" &amp;&amp;     $_POST['search-location'] !== "All") {
      $querystr .= " AND (wpostmeta2.meta_key = 'region' AND wpostmeta2.meta_value     = '".$_POST['search-location']."')";
  }
      $querystr .= " ORDER BY post_date DESC LIMIT 50";
  
  //Execute
  //echo $querystr;
  $pageposts = $wpdb-&gt;get_results($wpdb-&gt;prepare($querystr, OBJECT));
  </code></pre>
  
  <p>Any help would be great!!</p>