title: Mysql UNION on wordpress
body: <p>I need help to develop a wordpress customization. I have the following mysql query with <code>UNION</code> instruction:</p>
  
  <pre><code>SELECT 
      wp_posts.* 
  FROM wp_posts 
      INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) 
      LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) 
      LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key = 'dir_featured' ) 
  WHERE 
      ( wp_term_relationships.term_taxonomy_id IN (2151) ) AND 
      wp_posts.post_type = 'ait-dir-item' AND 
      ((wp_posts.post_status = 'publish')) AND 
      ( 
          ( 
          wp_postmeta.meta_key = 'dir_featured' AND 
          CAST(wp_postmeta.meta_value AS CHAR) = 'yes' 
          )
      ) 
  GROUP BY wp_posts.ID 
  UNION
  SELECT 
      wp_posts.* 
  FROM wp_posts 
      INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) 
      LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) 
      LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key = 'dir_featured' ) 
  WHERE 
      wp_term_relationships.term_taxonomy_id IN (2151) AND 
      wp_posts.post_type = 'ait-dir-item' AND 
      wp_posts.post_status = 'publish' AND 
      mt1.post_id IS NULL 
  GROUP BY wp_posts.ID 
  </code></pre>
  
  <p>I want to translate this query with wordpress parameters. Is it possible?</p>