kisukedeath

Custom wordpress query join multiple conditions

May 9th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.70 KB | None | 0 0
  1. Wordpress query join multiple conditions
  2. ------------------------------------------------------------
  3.  
  4. SELECT a.post_title, b.meta_key, b.meta_value
  5. FROM wp_posts a join wp_postmeta b
  6. on a.ID = b.post_id join wp_term_relationships c
  7. on a.ID = c.object_id join wp_term_taxonomy d
  8. on c.term_taxonomy_id = d.term_taxonomy_id
  9. WHERE a.post_type= 'article'
  10. AND a.post_status = 'publish'
  11. AND (b.meta_key = 'article_type' AND b.meta_value NOT IN (1,2)) OR
  12.    (b.meta_key = 'is_print' AND b.meta_value = 0) OR
  13.    (b.meta_key = 'is_sponsored' AND b.meta_value != 'on')
  14. AND d.term_taxonomy_id = 21 AND d.taxonomy = 'sector'
  15. GROUP BY a.ID
  16. HAVING COUNT(distinct b.meta_key) = 3
  17. ORDER BY a.post_DATE DESC LIMIT 20
Advertisement
Add Comment
Please, Sign In to add comment